| java.lang.Object java.io.InputStream org.apache.commons.httpclient.ContentLengthInputStream
ContentLengthInputStream | public class ContentLengthInputStream extends InputStream (Code) | | Cuts the wrapped InputStream off after a specified number of bytes.
Implementation note: Choices abound. One approach would pass
through the
InputStream.mark and
InputStream.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
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
InputStream.mark and
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 |
Method Summary | |
public int | available() | public void | close() | public int | read() | public int | read(byte[] b, int off, int len) Does standard
InputStream.read(byte[]intint) behavior, but
also notifies the watcher when the contents have been consumed.
Parameters: b - The byte array to fill. Parameters: off - Start filling at this position. Parameters: len - The number of bytes to attempt to read. | public int | read(byte[] b) Read more bytes from the stream.
Parameters: b - The byte array to put the new data in. | public long | skip(long n) Skips and discards a number of bytes from the input stream.
Parameters: n - The number of bytes to skip. |
ContentLengthInputStream | public ContentLengthInputStream(InputStream in, long contentLength)(Code) | | Creates a new length limited stream
Parameters: in - The stream to wrap Parameters: contentLength - The maximum number of bytes that can be read fromthe stream. Subsequent read operations will return -1. since: 3.0 |
close | public void close() throws IOException(Code) | | 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.
throws: IOException - If an IO problem occurs. |
read | public int read(byte[] b, int off, int len) throws java.io.IOException(Code) | | Does standard
InputStream.read(byte[]intint) behavior, but
also notifies the watcher when the contents have been consumed.
Parameters: b - The byte array to fill. Parameters: off - Start filling at this position. Parameters: len - The number of bytes to attempt to read. The number of bytes read, or -1 if the end of content has beenreached. throws: java.io.IOException - Should an error occur on the wrapped stream. |
skip | public long skip(long n) throws IOException(Code) | | Skips and discards a number of bytes from the input stream.
Parameters: n - The number of bytes to skip. The actual number of bytes skipped. <= 0 if no bytesare skipped. throws: IOException - If an error occurs while skipping bytes. See Also: InputStream.skip(long) |
|
|