Package org.apache.http.nio.reactor
Interface SessionInputBuffer
-
- All Known Implementing Classes:
SessionInputBufferImpl
public interface SessionInputBufferSession input buffer for non-blocking connections. This interface facilitates intermediate buffering of input data streamed from a source channel and reading buffered data to a destination, usuallyByteBufferorWritableByteChannel. This interface also provides methods for reading lines of text.- Since:
- 4.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description intfill(java.nio.channels.ReadableByteChannel src)Makes an attempt to fill the buffer with data from the givenReadableByteChannel.booleanhasData()Determines if the buffer contains data.intlength()Returns the length of this buffer.intread()Reads one byte from the buffer.intread(java.nio.ByteBuffer dst)Reads a sequence of bytes from this buffer into the destination buffer.intread(java.nio.ByteBuffer dst, int maxLen)Reads a sequence of bytes from this buffer into the destination buffer, up to the given maximum limit.intread(java.nio.channels.WritableByteChannel dst)Reads a sequence of bytes from this buffer into the destination channel.intread(java.nio.channels.WritableByteChannel dst, int maxLen)Reads a sequence of bytes from this buffer into the destination channel, up to the given maximum limit.java.lang.StringreadLine(boolean endOfStream)Attempts to transfer a complete line of characters up to a line delimiter from this buffer to a newly created string.booleanreadLine(CharArrayBuffer dst, boolean endOfStream)Attempts to transfer a complete line of characters up to a line delimiter from this buffer to the destination buffer.
-
-
-
Method Detail
-
hasData
boolean hasData()
Determines if the buffer contains data.- Returns:
trueif there is data in the buffer,falseotherwise.
-
length
int length()
Returns the length of this buffer.- Returns:
- buffer length.
-
fill
int fill(java.nio.channels.ReadableByteChannel src) throws java.io.IOException
Makes an attempt to fill the buffer with data from the givenReadableByteChannel.- Parameters:
src- the source channel- Returns:
- The number of bytes read, possibly zero, or
-1if the channel has reached end-of-stream. - Throws:
java.io.IOException- in case of an I/O error.
-
read
int read()
Reads one byte from the buffer. If the buffer is empty this method can throw a runtime exception. The exact type of runtime exception thrown by this method depends on implementation.- Returns:
- one byte
-
read
int read(java.nio.ByteBuffer dst, int maxLen)Reads a sequence of bytes from this buffer into the destination buffer, up to the given maximum limit. The exact number of bytes transferred depends on availability of data in this buffer and capacity of the destination buffer, but cannot be more thanmaxLenvalue.- Parameters:
dst- the destination buffer.maxLen- the maximum number of bytes to be read.- Returns:
- The number of bytes read, possibly zero.
-
read
int read(java.nio.ByteBuffer dst)
Reads a sequence of bytes from this buffer into the destination buffer. The exact number of bytes transferred depends on availability of data in this buffer and capacity of the destination buffer.- Parameters:
dst- the destination buffer.- Returns:
- The number of bytes read, possibly zero.
-
read
int read(java.nio.channels.WritableByteChannel dst, int maxLen) throws java.io.IOExceptionReads a sequence of bytes from this buffer into the destination channel, up to the given maximum limit. The exact number of bytes transferred depends on availability of data in this buffer, but cannot be more thanmaxLenvalue.- Parameters:
dst- the destination channel.maxLen- the maximum number of bytes to be read.- Returns:
- The number of bytes read, possibly zero.
- Throws:
java.io.IOException- in case of an I/O error.
-
read
int read(java.nio.channels.WritableByteChannel dst) throws java.io.IOException
Reads a sequence of bytes from this buffer into the destination channel. The exact number of bytes transferred depends on availability of data in this buffer.- Parameters:
dst- the destination channel.- Returns:
- The number of bytes read, possibly zero.
- Throws:
java.io.IOException- in case of an I/O error.
-
readLine
boolean readLine(CharArrayBuffer dst, boolean endOfStream) throws java.nio.charset.CharacterCodingException
Attempts to transfer a complete line of characters up to a line delimiter from this buffer to the destination buffer. If a complete line is available in the buffer, the sequence of chars is transferred to the destination buffer the method returnstrue. The line delimiter itself is discarded. If a complete line is not available in the buffer, this method returnsfalsewithout transferring anything to the destination buffer. IfendOfStreamparameter is set totruethis method assumes the end of stream has been reached and the content currently stored in the buffer should be treated as a complete line.The choice of a char encoding and line delimiter sequence is up to the specific implementations of this interface.
- Parameters:
dst- the destination buffer.endOfStream- end of stream flag- Returns:
trueif a sequence of chars representing a complete line has been transferred to the destination buffer,falseotherwise.- Throws:
java.nio.charset.CharacterCodingException- in case a character encoding or decoding error occurs.
-
readLine
java.lang.String readLine(boolean endOfStream) throws java.nio.charset.CharacterCodingExceptionAttempts to transfer a complete line of characters up to a line delimiter from this buffer to a newly created string. If a complete line is available in the buffer, the sequence of chars is transferred to a newly created string. The line delimiter itself is discarded. If a complete line is not available in the buffer, this method returnsnull. IfendOfStreamparameter is set totruethis method assumes the end of stream has been reached and the content currently stored in the buffer should be treated as a complete line.The choice of a char encoding and line delimiter sequence is up to the specific implementations of this interface.
- Parameters:
endOfStream- end of stream flag- Returns:
- a string representing a complete line, if available.
nullotherwise. - Throws:
java.nio.charset.CharacterCodingException- in case a character encoding or decoding error occurs.
-
-