org.apache.commons.httpclient
Class ContentLengthInputStream
java.lang.Object
|
+--java.io.InputStream
|
+--java.io.FilterInputStream
|
+--org.apache.commons.httpclient.ContentLengthInputStream
- public class ContentLengthInputStream
- extends FilterInputStream
Cuts the wrapped InputStream off after a specified number of bytes.
- Since:
- 2.0
- Author:
- Ortwin Gl?ck, Eric Johnson, Mike Bowler
Method Summary |
void |
close()
Reads until the end of the known length of content. |
int |
read()
Read the next byte from the stream |
int |
read(byte[] b)
Read more bytes from the stream. |
int |
read(byte[] b,
int off,
int len)
Does standard InputStream.read(byte[], int, int) behavior, but
also notifies the watcher when the contents have been consumed. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
ContentLengthInputStream
public ContentLengthInputStream(InputStream in,
int contentLength)
- Creates a new length limited stream
- Parameters:
in
- The stream to wrapcontentLength
- The maximum number of bytes that can be read from
the stream. Subsequent read operations will return -1.
close
public void close()
throws IOException
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.
- Overrides:
- close in class FilterInputStream
- Throws:
- IOException - If an IO problem occurs.
read
public int read()
throws IOException
- Read the next byte from the stream
- Overrides:
- read in class FilterInputStream
- Returns:
- The next byte or -1 if the end of stream has been reached.
- Throws:
- IOException - If an IO problem occurs
- See Also:
InputStream.read()
read
public int read(byte[] b,
int off,
int len)
throws IOException
- Does standard
InputStream.read(byte[], int, int)
behavior, but
also notifies the watcher when the contents have been consumed.
- Overrides:
- read in class FilterInputStream
- Parameters:
b
- The byte array to fill.off
- Start filling at this position.len
- The number of bytes to attempt to read.- Returns:
- The number of bytes read, or -1 if the end of content has been
reached.
- Throws:
- IOException - Should an error occur on the wrapped stream.
read
public int read(byte[] b)
throws IOException
- Read more bytes from the stream.
- Overrides:
- read in class FilterInputStream
- Parameters:
b
- The byte array to put the new data in.- Returns:
- The number of bytes read into the buffer.
- Throws:
- IOException - If an IO problem occurs
- See Also:
InputStream.read(byte[])
Copyright © 2001-2003 Apache Software Foundation. All Rights Reserved.