java.lang.Object | ||
↳ | java.io.InputStream | |
↳ | org.apache.http.impl.io.ContentLengthInputStream |
Stream that cuts off after a specified number of bytes. 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.
Implementation note: Choices abound. One approach would pass
through the mark(int)
and reset()
calls to
the underlying stream. That's tricky, though, because you then have to
start duplicating the work of keeping track of how much a reset rewinds.
Further, you have to watch out for the "readLimit", and since the semantics
for the readLimit leave room for differing implementations, you might get
into a lot of trouble.
Alternatively, you could make this class extend
BufferedInputStream
and then use the protected members of that class to avoid duplicated effort.
That solution has the side effect of adding yet another possible layer of
buffering.
Then, there is the simple choice, which this takes - simply don't
support mark(int)
and reset()
. That choice
has the added benefit of keeping this class very simple.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new length limited stream
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Reads until the end of the known length of content. | |||||||||||
Read more bytes from the stream.
| |||||||||||
Read the next byte from the stream
| |||||||||||
Does standard
read(byte[], int, int) behavior, but
also notifies the watcher when the contents have been consumed. | |||||||||||
Skips and discards a number of bytes from the input stream.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.io.InputStream
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.io.Closeable
| |||||||||||
From interface
java.lang.AutoCloseable
|
Creates a new length limited stream
in | The session input buffer to wrap |
---|---|
contentLength | The maximum number of bytes that can be read from the stream. Subsequent read operations will return -1. |
Reads until the end of the known length of content.
Does not close the underlying socket input, but instead leaves it primed to parse the next response.
IOException | If an IO problem occurs. |
---|
Read more bytes from the stream.
b | The byte array to put the new data in. |
---|
IOException | If an IO problem occurs |
---|
Read the next byte from the stream
IOException | If an IO problem occurs |
---|
Does standard read(byte[], int, int)
behavior, but
also notifies the watcher when the contents have been consumed.
b | The byte array to fill. |
---|---|
off | Start filling at this position. |
len | The number of bytes to attempt to read. |
IOException | Should an error occur on the wrapped stream. |
---|
Skips and discards a number of bytes from the input stream.
n | The number of bytes to skip. |
---|
IOException | If an error occurs while skipping bytes. |
---|