Package ej.hoka.io
Class ChunkedMessageBodyInputStream
- java.lang.Object
-
- java.io.InputStream
-
- ej.hoka.io.ChunkedMessageBodyInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ChunkedMessageBodyInputStream extends java.io.InputStreamInput 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 Summary
Constructors Constructor Description ChunkedMessageBodyInputStream(java.io.InputStream is)Creates a newChunkedMessageBodyInputStreamusing the InputStreamisas the underlying data source.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns the number of available bytes to read.voidclose()Reads all remaining message body data and closes this input stream.intread()Reads the next byte from the InputStream used in the constructor.intread(byte[] data, int offset, int length)Reads up tolengthbytes to the byte arraydatastarting withoffset.
-
-
-
Method Detail
-
available
public int available() throws java.io.IOExceptionReturns the number of available bytes to read.- Overrides:
availablein classjava.io.InputStream- Returns:
- the number of available bytes to read.
- Throws:
java.io.IOException- if theChunkedMessageBodyInputStreamis already closed.
-
close
public void close() throws java.io.IOExceptionReads 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.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException- when an error occurs while closing the stream
-
read
public int read() throws java.io.IOExceptionReads the next byte from the InputStream used in the constructor.- Specified by:
readin classjava.io.InputStream- Returns:
- the next byte value (0-255) or -1 if the end of the InputStream has been reached.
- Throws:
java.io.IOException- when the InputStream has already been closed.
-
read
public int read(byte[] data, int offset, int length) throws java.io.IOExceptionReads up tolengthbytes to the byte arraydatastarting withoffset. The method tries to readlengthbytes (if there are at leastlengthbytes in the InputStream used in the constructor. Otherwise reads just the available number of bytes).- Overrides:
readin classjava.io.InputStream- Parameters:
data- the byte array to store the bytes read from the underlying InputStreamoffset- the position in the byte arraydatato store the bytes read from the InputStream.length- number of bytes to store in the byte arraydata(if the number of bytes available in the InputStream are at leastlength) If less thanlengthbytes are left in the InputStream, only the remaining bytes are stored in the byte arraydata.- Returns:
- the number of bytes stored in the byte array
data, or -1 if no bytes can be stored in the byte arraydata. - Throws:
java.io.IOException- when the end of InputStream has already been reached.
-
-