net.noderunner.http
Class ChunkedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by net.noderunner.http.ChunkedInputStream
All Implemented Interfaces:
java.io.Closeable

public class ChunkedInputStream
extends java.io.InputStream

An InputStream wrapper supporting the chunked transfer encoding.

Author:
Elias Ross
See Also:
ChunkedOutputStream

Constructor Summary
ChunkedInputStream(java.io.InputStream stream)
          Constructs a chunked input stream wrapping input.
 
Method Summary
 void close()
          Closes the underlying input stream.
 MessageHeaders getEntityHeaders()
          Returns "trailer" entity headers, which appear at the end of a chunked encoding request.
 boolean isEndChunk()
          Returns true if the end chunk was read.
 int read()
          Reads and return a single byte from this input stream, or -1 if end of file has been encountered.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from the input stream into an array of bytes.
 java.lang.String toString()
          Returns a debug string.
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChunkedInputStream

public ChunkedInputStream(java.io.InputStream stream)
Constructs a chunked input stream wrapping input.

Parameters:
stream - Must be non-null.
Method Detail

close

public void close()
           throws java.io.IOException
Closes the underlying input stream.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.

Overrides:
read in class java.io.InputStream
Parameters:
b - The buffer into which the data is read
off - The start offset into array b at which the data is written
len - The maximum number of bytes to read
Throws:
java.io.IOException - if an input/output error occurs

read

public int read()
         throws java.io.IOException
Reads and return a single byte from this input stream, or -1 if end of file has been encountered.

Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException - if an input/output error occurs

getEntityHeaders

public MessageHeaders getEntityHeaders()
Returns "trailer" entity headers, which appear at the end of a chunked encoding request. Returns null if not at the end of input. These will only appear when isEndChunk() returns true. See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6.1


isEndChunk

public boolean isEndChunk()
Returns true if the end chunk was read.


toString

public java.lang.String toString()
Returns a debug string.

Overrides:
toString in class java.lang.Object


Copyright © 2010. All Rights Reserved.