This class cuts the wrapped InputStream 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 invocation of subsequent HTTP 1.1 calls, 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 {@link InputStream#mark} and {@link InputStream#reset} calls tothe 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 {@link java.io.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 {@link InputStream#mark} and {@link InputStream#reset}. That choice has the added benefit of keeping this class very simple.
@author Ortwin Glueck @author Eric Johnson @author Mike Bowler @since 2.0
|
|
|
|
|
|