Package sun.net.www.http
Class ChunkedInputStream
- java.lang.Object
-
- java.io.InputStream
-
- sun.net.www.http.ChunkedInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Hurryable
public class ChunkedInputStream extends InputStream implements Hurryable
AChunkedInputStreamprovides 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
ChunkedInputStreamis alsoHurryableso it can be hurried to the end of the stream if the bytes are available on the underlying stream.
-
-
Constructor Summary
Constructors Constructor Description ChunkedInputStream(InputStream in, HttpClient hc, MessageHeader responses)Creates aChunkedInputStreamand saves its arguments, for later use.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns the number of bytes that can be read from this input stream without blocking.voidclose()Close the stream by either returning the connection to the keep alive cache or closing the underlying stream.booleanhurry()Hurry the input stream by reading everything from the underlying stream.intread()See the general contract of thereadmethod ofInputStream.intread(byte[] b, int off, int len)Reads bytes from this stream into the specified byte array, starting at the given offset.-
Methods inherited from class java.io.InputStream
mark, markSupported, read, reset, skip
-
-
-
-
Constructor Detail
-
ChunkedInputStream
public ChunkedInputStream(InputStream in, HttpClient hc, MessageHeader responses) throws IOException
Creates aChunkedInputStreamand saves its arguments, for later use.- Parameters:
in- the underlying input stream.hc- the HttpClientresponses- the MessageHeader that should be populated with optional trailers.- Throws:
IOException
-
-
Method Detail
-
read
public int read() throws IOExceptionSee the general contract of thereadmethod ofInputStream.- Specified by:
readin classInputStream- Returns:
- the next byte of data, or
-1if the end of the stream is reached. - Throws:
IOException- if an I/O error occurs.- See Also:
FilterInputStream.in
-
read
public int read(byte[] b, int off, int len) throws IOExceptionReads bytes from this stream into the specified byte array, starting at the given offset.- Overrides:
readin classInputStream- Parameters:
b- destination buffer.off- offset at which to start storing bytes.len- maximum number of bytes to read.- Returns:
- the number of bytes read, or
-1if the end of the stream has been reached. - Throws:
IOException- if an I/O error occurs.- See Also:
InputStream.read()
-
available
public int available() throws IOExceptionReturns the number of bytes that can be read from this input stream without blocking.- Overrides:
availablein classInputStream- Returns:
- the number of bytes that can be read from this input stream without blocking.
- Throws:
IOException- if an I/O error occurs.- See Also:
FilterInputStream.in
-
close
public void close() throws IOExceptionClose the stream by either returning the connection to the keep alive cache or closing the underlying stream.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.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException- if an I/O error occurs.
-
hurry
public boolean hurry()
Hurry the input stream by reading everything from the underlying stream. If the last chunk (and optional trailers) can be read without blocking then the stream is considered hurried.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.
-
-