Package ej.hoka.io
Class IdentityMessageBodyInputStream
- java.lang.Object
-
- java.io.InputStream
-
- ej.hoka.io.IdentityMessageBodyInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class IdentityMessageBodyInputStream extends java.io.InputStreamIdentity input stream. Wraps anInputStreamand all of the operations onIdentityMessageBodyInputStreamare delegated to this underlyingInputStream.
-
-
Constructor Summary
Constructors Constructor Description IdentityMessageBodyInputStream(java.io.InputStream is, int bodyLength)Creates a new instance ofIdentityMessageBodyInputStreamwith theInputStreamiswith the predefined lengthbodyLength.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns the number of bytes that can be read (or skipped over) from this input stream without blocking.voidclose()Reads all remaining message body data and then close this input stream.intread()Reads the next byte of data from the input stream.intread(byte[] data, int offset, int length)Reads up tolengthbytes of data from the underlyingInputStreaminto an array of bytes.
-
-
-
Constructor Detail
-
IdentityMessageBodyInputStream
public IdentityMessageBodyInputStream(java.io.InputStream is, int bodyLength)Creates a new instance ofIdentityMessageBodyInputStreamwith theInputStreamiswith the predefined lengthbodyLength. ThebodyLengthshould be the maximum number of bytes can be read from the InputStream.- Parameters:
is- the underlyingInputStreamto read the body content of the HTTP message bodybodyLength- the number of bytes can be read from the underlying InputStream.
-
-
Method Detail
-
available
public int available() throws java.io.IOExceptionReturns the number of bytes that can be read (or skipped over) from this input stream without blocking.- Overrides:
availablein classjava.io.InputStream- Returns:
- the number of available bytes could be read from the stream
- Throws:
java.io.IOException- if IO Error occurs.
-
close
public void close() throws java.io.IOExceptionReads all remaining message body data and then close 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 of data from the input stream. The byte value is returned as an int in the range of 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Specified by:
readin classjava.io.InputStream- Returns:
- the next byte of data from the input stream, or -1 if the end of the input stream has been reached.
- Throws:
java.io.IOException- If a premature EOF is reached, this stream is closed and an IOException is thrown.
-
read
public int read(byte[] data, int offset, int length) throws java.io.IOExceptionReads up tolengthbytes of data from the underlyingInputStreaminto an array of bytes. An attempt is made to read as many aslengthbytes, but the amount of bytes can be read from theInputStreamcould be less thanlength, even0. The number of bytes actually read are returned as an integer.- Overrides:
readin classjava.io.InputStream- Parameters:
data- the byte array to store the read bytes from the underlyingInputStreamoffset- the starting index of byte arraydatato store the byteslength- the number of bytes intended to be read by the caller of this method- Returns:
- the number of bytes actually read from the underlying
InputStream. If the end of stream has been reached, returns-1 - Throws:
java.io.IOException- thrown in the following cases:- if this stream is already closed
- if an EOF is reached prematurely on the underlying InputStream
- See Also:
InputStream.read(byte[], int, int)
-
-