Note that this class NEVER closes the underlying stream, even when close gets called. Instead, it will read until the "end" of its chunking on close, which allows for the seamless execution of subsequent HTTP 1.1 requests, while not requiring the client to remember to read the entire contents of the response.
| Modifier and Type | Field and Description |
|---|---|
| private final CharArrayBuffer | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private long | chunkSize
The chunk size |
| private boolean | closed
True if this stream is closed |
| private final MessageConstraints | |
| private boolean | eof
True if we've reached the end of stream |
| private Header[] | |
| private final SessionInputBuffer | in
The session input buffer |
| private long | pos
The current position within the current chunk |
| private int |
| Access | Constructor and Description |
|---|---|
| public | ChunkedInputStream(final SessionInputBuffer
The session input buffer in, final MessageConstraints Message constraints. If constraints)null
MessageConstraints#DEFAULT will be used.Wraps session input stream and reads chunk coded input. |
| public | ChunkedInputStream(final SessionInputBuffer
The session input buffer in)Wraps session input stream and reads chunk coded input. |
| Modifier and Type | Method and Description |
|---|---|
| public int | available()
Overrides java. |
| public void | close()
Overrides java. Implements java. |
| private long | getChunkSize()
Expects the stream to start with a chunksize in hex with optional comments after a semicolon. |
| public Header[] | |
| private void | |
| private void | |
| public int | Returns: -1 of the end of the stream has been reached or the next data byteImplements abstract java. Returns all the data in a chunked stream in coalesced form. |
| public int | Returns: The number of bytes returned or -1 if the end of stream has been reached.The byte array that will hold the contents from the stream. b, final int The offset into the byte array at which bytes will start to be
placed. off, final int the maximum number of bytes that can be returned. len)Overrides java. |
| public int | Returns: The number of bytes returned or -1 if the end of stream has been reached.The byte array that will hold the contents from the stream. b)Overrides java. |
| buffer | back to summary |
|---|---|
| private final CharArrayBuffer buffer | |
| BUFFER_SIZE | back to summary |
|---|---|
| private static final int BUFFER_SIZE | |
| CHUNK_CRLF | back to summary |
|---|---|
| private static final int CHUNK_CRLF | |
| CHUNK_DATA | back to summary |
|---|---|
| private static final int CHUNK_DATA | |
| CHUNK_INVALID | back to summary |
|---|---|
| private static final int CHUNK_INVALID | |
| CHUNK_LEN | back to summary |
|---|---|
| private static final int CHUNK_LEN | |
| chunkSize | back to summary |
|---|---|
| private long chunkSize The chunk size | |
| closed | back to summary |
|---|---|
| private boolean closed True if this stream is closed | |
| constraints | back to summary |
|---|---|
| private final MessageConstraints constraints | |
| eof | back to summary |
|---|---|
| private boolean eof True if we've reached the end of stream | |
| footers | back to summary |
|---|---|
| private Header[] footers | |
| in | back to summary |
|---|---|
| private final SessionInputBuffer in The session input buffer | |
| pos | back to summary |
|---|---|
| private long pos The current position within the current chunk | |
| state | back to summary |
|---|---|
| private int state | |
| ChunkedInputStream | back to summary |
|---|---|
| public ChunkedInputStream(final SessionInputBuffer in, final MessageConstraints constraints) Wraps session input stream and reads chunk coded input.
| |
| ChunkedInputStream | back to summary |
|---|---|
| public ChunkedInputStream(final SessionInputBuffer in) Wraps session input stream and reads chunk coded input.
| |
| available | back to summary |
|---|---|
| public int available() throws IOException Overrides java. Doc from java. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes. Note that while some implementations of A subclass's implementation of this method may choose to throw an
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Upon close, this reads the remainder of the chunked message, leaving the underlying socket at a position to start reading the next response without scanning.
| |
| getChunkSize | back to summary |
|---|---|
| private long getChunkSize() throws IOException Expects the stream to start with a chunksize in hex with optional comments after a semicolon. The line must end with a CRLF: "a3; some comment\r\n" Positions the stream at the start of the next line. | |
| getFooters | back to summary |
|---|---|
| public Header[] getFooters() | |
| nextChunk | back to summary |
|---|---|
| private void nextChunk() throws IOException Read the next chunk.
| |
| parseTrailerHeaders | back to summary |
|---|---|
| private void parseTrailerHeaders() throws IOException Reads and stores the Trailer headers.
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements abstract java. Returns all the data in a chunked stream in coalesced form. A chunk is followed by a CRLF. The method returns -1 as soon as a chunksize of 0 is detected. Trailer headers are read automatically at the end of the stream and can be obtained with the getResponseFooters() method.
| |
| read | back to summary |
|---|---|
| public int read(final byte[] b, final int off, final int len) throws IOException Overrides java. Read some bytes from the stream.
| |
| read | back to summary |
|---|---|
| public int read(final byte[] b) throws IOException Overrides java. Read some bytes from the stream.
| |