public class ChunkedMessageBodyInputStream
extends java.io.InputStream
Input Stream for reading HTTP 1.1 Chunked transfer encoding data.
Each chunk starts with the number of octets of the data it embeds, expressed as a hexadecimal number in ASCII, followed by optional parameters (chunk extension) and a terminating CRLF sequence, followed by the chunk data. The chunk is terminated by CRLF. If chunk extensions are provided, the chunk size is terminated by a semicolon followed with the extension name and an optional equal sign and value. (chunk extensions are skipped).
Constructor and Description |
---|
ChunkedMessageBodyInputStream(java.io.InputStream is)
Creates a new
ChunkedMessageBodyInputStream using the InputStream is as the underlying
data source. |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the number of available bytes to read.
|
void |
close()
Reads all remaining message body data and closes this input stream.
|
int |
read()
Reads the next byte from the InputStream used in the constructor.
|
int |
read(byte[] data,
int offset,
int length)
Reads up to
length bytes to the byte array data starting with offset . |
public ChunkedMessageBodyInputStream(java.io.InputStream is)
Creates a new ChunkedMessageBodyInputStream
using the InputStream is
as the underlying
data source.
is
- InputStream to read from.public int available() throws java.io.IOException
Returns the number of available bytes to read.
available
in class java.io.InputStream
java.io.IOException
- if the ChunkedMessageBodyInputStream
is already closed.public void close() throws java.io.IOException
Reads all remaining message body data and closes this input stream. This method DOES NOT close the underlying stream (i.e. the TCP connection stream). It is the responsibility of the HTTPSession to close the underlying stream.
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
- when an error occurs while closing the streampublic int read() throws java.io.IOException
Reads the next byte from the InputStream used in the constructor.
read
in class java.io.InputStream
java.io.IOException
- when the InputStream has already been closed.public int read(byte[] data, int offset, int length) throws java.io.IOException
Reads up to length
bytes to the byte array data
starting with offset
. The
method tries to read length
bytes (if there are at least length
bytes in the
InputStream used in the constructor. Otherwise reads just the available number of bytes).
read
in class java.io.InputStream
data
- the byte array to store the bytes read from the underlying InputStreamoffset
- the position in the byte array data
to store the bytes read from the InputStream.length
- number of bytes to store in the byte array data
(if the number of bytes available in the
InputStream are at least length
) If less than length
bytes are left in the
InputStream, only the remaining bytes are stored in the byte array data
.data
, or -1 if no bytes can be stored in the
byte array data
.java.io.IOException
- when the end of InputStream has already been reached.