public class ChunkedInputStream extends java.io.InputStream implements Hurryable
ChunkedInputStream
provides a stream for reading a body of a http message that can be sent as a series
of chunks, each with its own size indicator. Optionally the last chunk can be followed by trailers containing
entity-header fields.
A ChunkedInputStream
is also Hurryable
so it can be hurried to the end of the stream if the
bytes are available on the underlying stream.
Constructor and Description |
---|
ChunkedInputStream(java.io.InputStream in,
HttpClient hc,
sun.net.www.MessageHeader responses)
Creates a
ChunkedInputStream and saves its arguments, for later use. |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the number of bytes that can be read from this input stream without blocking.
|
void |
close()
Close the stream by either returning the connection to the keep alive cache or closing the underlying stream.
|
boolean |
hurry()
Hurry the input stream by reading everything from the underlying stream.
|
int |
read()
See the general contract of the
read method of InputStream . |
int |
read(byte[] b,
int off,
int len)
Reads bytes from this stream into the specified byte array, starting at the given offset.
|
public ChunkedInputStream(java.io.InputStream in, HttpClient hc, sun.net.www.MessageHeader responses) throws java.io.IOException
ChunkedInputStream
and saves its arguments, for later use.in
- the underlying input stream.hc
- the HttpClientresponses
- the MessageHeader that should be populated with optional trailers.java.io.IOException
public int read() throws java.io.IOException
read
method of InputStream
.read
in class java.io.InputStream
-1
if the end of the stream is reached.java.io.IOException
- if an I/O error occurs.FilterInputStream.in
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
b
- destination buffer.off
- offset at which to start storing bytes.len
- maximum number of bytes to read.-1
if the end of the stream has been reached.java.io.IOException
- if an I/O error occurs.public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
- if an I/O error occurs.FilterInputStream.in
public void close() throws java.io.IOException
If the chunked response hasn't been completely read we try to "hurry" to the end of the response. If this is possible (without blocking) then the connection can be returned to the keep alive cache.
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
- if an I/O error occurs.public boolean hurry()
Note that if an error has occured or we can't get to last chunk without blocking then this stream can't be hurried and should be closed.