@NotThreadSafe public class ContentLengthInputStream extends java.io.InputStream
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.
| 构造器和说明 |
|---|
ContentLengthInputStream(SessionInputBuffer in,
long contentLength)
Wraps a session input buffer and cuts off output after a defined number
of bytes.
|
| 限定符和类型 | 方法和说明 |
|---|---|
int |
available() |
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. |
long |
skip(long n)
Skips and discards a number of bytes from the input stream.
|
public ContentLengthInputStream(SessionInputBuffer in, long contentLength)
in - The session input buffercontentLength - The maximum number of bytes that can be read from
the stream. Subsequent read operations will return -1.public void close()
throws java.io.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.
close 在接口中 java.io.Closeableclose 在接口中 java.lang.AutoCloseableclose 在类中 java.io.InputStreamjava.io.IOException - If an IO problem occurs.public int available()
throws java.io.IOException
available 在类中 java.io.InputStreamjava.io.IOExceptionpublic int read()
throws java.io.IOException
read 在类中 java.io.InputStreamjava.io.IOException - If an IO problem occursInputStream.read()public int read(byte[] b,
int off,
int len)
throws java.io.IOException
InputStream.read(byte[], int, int) behavior, but
also notifies the watcher when the contents have been consumed.read 在类中 java.io.InputStreamb - The byte array to fill.off - Start filling at this position.len - The number of bytes to attempt to read.java.io.IOException - Should an error occur on the wrapped stream.public int read(byte[] b)
throws java.io.IOException
read 在类中 java.io.InputStreamb - The byte array to put the new data in.java.io.IOException - If an IO problem occursInputStream.read(byte[])public long skip(long n)
throws java.io.IOException
skip 在类中 java.io.InputStreamn - The number of bytes to skip.java.io.IOException - If an error occurs while skipping bytes.InputStream.skip(long)