Content-Length header.
Entities transferred using this stream can be maximum Long#MAX_VALUE
long.
Note that this class NEVER closes the underlying stream, even when
close() gets called. Instead, it will read until the "end" of
its limit 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 SessionInputBuffer | |
| private static final int | |
| private boolean | closed
True if the stream is closed. |
| private final long | contentLength
The maximum number of bytes that can be read from the stream. |
| private final InputStream | |
| private long | pos
The current position |
| Access | Constructor and Description |
|---|---|
| public | ContentLengthInputStream(final SessionInputBuffer
Session input buffer buffer, final InputStream Input stream inputStream, final long The maximum number of bytes that can be read from
the stream. Subsequent read operations will return -1. contentLength)Default constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public int | available()
Overrides java. |
| public void | close()
Overrides java. Implements java. Reads until the end of the known length of content. |
| public int | Returns: The next byte or -1 if the end of stream has been reached.Implements abstract java. |
| public int | Returns: The number of bytes read, or -1 if the end of content has been reached.The byte array to fill. b, final int Start filling at this position. off, final int The number of bytes to attempt to read. len)Overrides java. InputStream#read(byte[], int, int) behavior, but
also notifies the watcher when the contents have been consumed.
|
| public int | Returns: The number of bytes read into the buffer.The byte array to put the new data in. b)Overrides java. |
| public long | Returns: The actual number of bytes skipped. ≤ 0 if no bytes are skipped.The number of bytes to skip. n)Overrides java. |
| buffer | back to summary |
|---|---|
| private final SessionInputBuffer buffer | |
| BUFFER_SIZE | back to summary |
|---|---|
| private static final int BUFFER_SIZE | |
| closed | back to summary |
|---|---|
| private boolean closed True if the stream is closed. | |
| contentLength | back to summary |
|---|---|
| private final long contentLength The maximum number of bytes that can be read from the stream. Subsequent read operations will return -1. | |
| inputStream | back to summary |
|---|---|
| private final InputStream inputStream | |
| pos | back to summary |
|---|---|
| private long pos The current position | |
| ContentLengthInputStream | back to summary |
|---|---|
| public ContentLengthInputStream(final SessionInputBuffer buffer, final InputStream inputStream, final long contentLength) Default constructor.
| |
| 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. Reads until the end of the known length of content. Does NOT close the underlying stream, but instead leaves it primed to parse the next response.
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements abstract java. Read the next byte from the stream
| |
| read | back to summary |
|---|---|
| public int read(final byte[] b, final int off, final int len) throws IOException Overrides java. Does standard
| |
| read | back to summary |
|---|---|
| public int read(final byte[] b) throws IOException Overrides java. Read more bytes from the stream.
| |
| skip | back to summary |
|---|---|
| public long skip(final long n) throws IOException Overrides java. Skips and discards a number of bytes from the input stream.
| |