Package org.apache.hc.core5.http.io
Interface SessionInputBuffer
- All Known Implementing Classes:
SessionInputBufferImpl
public interface SessionInputBuffer
Session input buffer for HTTP/1.1 blocking connections.
This interface facilitates intermediate buffering of input data streamed from an input stream and provides methods for reading lines of text.
- Since:
- 4.0
-
Method Summary
Modifier and TypeMethodDescriptionint
Returns available space in the buffer.int
capacity()
Returns total capacity of the bufferReturnsHttpTransportMetrics
for this session buffer.int
length()
Returns length data stored in the bufferint
read
(byte[] b, int off, int len, InputStream inputStream) Reads up tolen
bytes of data from the session buffer into an array of bytes.int
read
(byte[] b, InputStream inputStream) Reads some number of bytes from the session buffer and stores them into the buffer arrayb
.int
read
(InputStream inputStream) Reads the next byte of data from this session buffer.int
readLine
(CharArrayBuffer buffer, InputStream inputStream) Reads a complete line of characters up to a line delimiter from this session buffer into the given line buffer.
-
Method Details
-
length
int length()Returns length data stored in the buffer- Returns:
- data length
-
capacity
int capacity()Returns total capacity of the buffer- Returns:
- total capacity
-
available
int available()Returns available space in the buffer.- Returns:
- available space.
-
read
Reads up tolen
bytes of data from the session buffer into an array of bytes. An attempt is made to read as many aslen
bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.This method blocks until input data is available, end of file is detected, or an exception is thrown.
If
off
is negative, orlen
is negative, oroff+len
is greater than the length of the arrayb
, then anIndexOutOfBoundsException
is thrown.- Parameters:
b
- the buffer into which the data is read.off
- the start offset in arrayb
at which the data is written.len
- the maximum number of bytes to read.inputStream
- Input stream- Returns:
- the total number of bytes read into the buffer, or
-1
if there is no more data because the end of the stream has been reached. - Throws:
IOException
- if an I/O error occurs.
-
read
Reads some number of bytes from the session buffer and stores them into the buffer arrayb
. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.- Parameters:
b
- the buffer into which the data is read.inputStream
- Input stream- Returns:
- the total number of bytes read into the buffer, or
-1
is there is no more data because the end of the stream has been reached. - Throws:
IOException
- if an I/O error occurs.
-
read
Reads the next byte of data from this session buffer. The value byte is returned as anint
in the range0
to255
. 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.- Parameters:
inputStream
- Input stream- Returns:
- the next byte of data, or
-1
if the end of the stream is reached. - Throws:
IOException
- if an I/O error occurs.
-
readLine
Reads a complete line of characters up to a line delimiter from this session buffer into the given line buffer. The number of chars actually read is returned as an integer. The line delimiter itself is discarded. If no char is available because the end of the stream has been reached, the value-1
is returned. This method blocks until input data is available, end of file is detected, or an exception is thrown.The choice of a char encoding and line delimiter sequence is up to the specific implementations of this interface.
- Parameters:
buffer
- the line buffer, one line of characters upon returninputStream
- Input stream- Returns:
- the total number of bytes read into the buffer, or
-1
is there is no more data because the end of the stream has been reached. - Throws:
IOException
- if an I/O error occurs.
-
getMetrics
HttpTransportMetrics getMetrics()ReturnsHttpTransportMetrics
for this session buffer.- Returns:
- transport metrics.
-