Top Description Fields Constructors Methods
org.apache.hc.core5.http.impl.io

public Class SessionInputBufferImpl

extends Object
implements SessionInputBuffer
Class Inheritance
All Implemented Interfaces
org.apache.hc.core5.http.io.SessionInputBuffer
Imports
java.io.IOException, .InputStream, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.CharsetDecoder, .CoderResult, org.apache.hc.core5.http.Chars, .MessageConstraintException, org.apache.hc.core5.http.impl.BasicHttpTransportMetrics, org.apache.hc.core5.http.io.HttpTransportMetrics, .SessionInputBuffer, org.apache.hc.core5.util.Args, .ByteArrayBuffer, .CharArrayBuffer

Abstract base class for session input buffers that stream data from an arbitrary InputStream. This class buffers input data in an internal byte array for optimal input performance.

readLine(CharArrayBuffer, InputStream) method of this class treat a lone LF as valid line delimiters in addition to CR-LF required by the HTTP specification.

Since
4.3

Field Summary

Modifier and TypeField and Description
private final byte[]
private int
private int
private CharBuffer
private final CharsetDecoder
private final ByteArrayBuffer
private final int
private final BasicHttpTransportMetrics
private final int

Constructor Summary

AccessConstructor and Description
public
SessionInputBufferImpl(final BasicHttpTransportMetrics
HTTP transport metrics.
metrics
,
final int
buffer size. Must be a positive number.
bufferSize
,
final int
size limit below which data chunks should be buffered in memory in order to minimize native method invocations on the underlying network socket. The optimal value of this parameter can be platform specific and defines a trade-off between performance of memory copy operations and that of native method invocation. If negative default chunk limited will be used.
minChunkLimit
,
final int
maximum line length.
maxLineLen
,
final CharsetDecoder
charDecoder to be used for decoding HTTP protocol elements. If null simple type cast will be used for byte to char conversion.
charDecoder
)

Creates new instance of SessionInputBufferImpl.

public
SessionInputBufferImpl(final BasicHttpTransportMetrics metrics, final int bufferSize)

public
SessionInputBufferImpl(final int bufferSize, final int maxLineLen)

public
SessionInputBufferImpl(final int bufferSize, final CharsetDecoder decoder)

public
SessionInputBufferImpl(final int bufferSize)

Method Summary

Modifier and TypeMethod and Description
private int
appendDecoded(final CharArrayBuffer charbuffer, final ByteBuffer bbuf)

public int
available()

Implements org.apache.hc.core5.http.io.SessionInputBuffer.available.

Returns available space in the buffer.
public int
capacity()

Implements org.apache.hc.core5.http.io.SessionInputBuffer.capacity.

Returns total capacity of the buffer
public void
public int
fillBuffer(final InputStream inputStream)

public HttpTransportMetrics
private int
handleDecodingResult(final CoderResult result, final CharArrayBuffer charBuffer)

public boolean
public int
length()

Implements org.apache.hc.core5.http.io.SessionInputBuffer.length.

Returns length data stored in the buffer
private int

Returns:

HTTP line as a string
lineFromLineBuffer
(final CharArrayBuffer charBuffer)

Reads a complete line of characters up to a line delimiter from this session buffer.

private int
lineFromReadBuffer(final CharArrayBuffer charbuffer, final int position)

public int
read(final InputStream
Input stream
inputStream
)

Implements org.apache.hc.core5.http.io.SessionInputBuffer.read.

Reads the next byte of data from this session buffer.
public int
read(final byte[]
the buffer into which the data is read.
b
,
final int
the start offset in array b at which the data is written.
off
,
final int
the maximum number of bytes to read.
len
,
final InputStream
Input stream
inputStream
)

Implements org.apache.hc.core5.http.io.SessionInputBuffer.read.

Reads up to len bytes of data from the session buffer into an array of bytes.
public int
read(final byte[]
the buffer into which the data is read.
b
,
final InputStream
Input stream
inputStream
)

Implements org.apache.hc.core5.http.io.SessionInputBuffer.read.

Reads some number of bytes from the session buffer and stores them into the buffer array b.
public int

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.
readLine
(final CharArrayBuffer
the line buffer, one line of characters upon return
charBuffer
,
final InputStream
Input stream
inputStream
)

Implements org.apache.hc.core5.http.io.SessionInputBuffer.readLine.

Reads a complete line of characters up to a line delimiter from this session buffer into the given line buffer.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
private final byte[] buffer
bufferLenback to summary
private int bufferLen
bufferPosback to summary
private int bufferPos
cbufback to summary
private CharBuffer cbuf
decoderback to summary
private final CharsetDecoder decoder
lineBufferback to summary
private final ByteArrayBuffer lineBuffer
maxLineLenback to summary
private final int maxLineLen
metricsback to summary
private final BasicHttpTransportMetrics metrics
minChunkLimitback to summary
private final int minChunkLimit

Constructor Detail

SessionInputBufferImplback to summary
public SessionInputBufferImpl(final BasicHttpTransportMetrics metrics, final int bufferSize, final int minChunkLimit, final int maxLineLen, final CharsetDecoder charDecoder)

Creates new instance of SessionInputBufferImpl.

Parameters
metrics:BasicHttpTransportMetrics

HTTP transport metrics.

bufferSize:int

buffer size. Must be a positive number.

minChunkLimit:int

size limit below which data chunks should be buffered in memory in order to minimize native method invocations on the underlying network socket. The optimal value of this parameter can be platform specific and defines a trade-off between performance of memory copy operations and that of native method invocation. If negative default chunk limited will be used.

maxLineLen:int

maximum line length.

charDecoder:CharsetDecoder

charDecoder to be used for decoding HTTP protocol elements. If null simple type cast will be used for byte to char conversion.

SessionInputBufferImplback to summary
public SessionInputBufferImpl(final BasicHttpTransportMetrics metrics, final int bufferSize)
SessionInputBufferImplback to summary
public SessionInputBufferImpl(final int bufferSize, final int maxLineLen)
SessionInputBufferImplback to summary
public SessionInputBufferImpl(final int bufferSize, final CharsetDecoder decoder)
SessionInputBufferImplback to summary
public SessionInputBufferImpl(final int bufferSize)

Method Detail

appendDecodedback to summary
private int appendDecoded(final CharArrayBuffer charbuffer, final ByteBuffer bbuf) throws IOException
availableback to summary
public int available()

Implements org.apache.hc.core5.http.io.SessionInputBuffer.available.

Doc from org.apache.hc.core5.http.io.SessionInputBuffer.available.

Returns available space in the buffer.

Returns:int

available space.

Annotations
@Override
capacityback to summary
public int capacity()

Implements org.apache.hc.core5.http.io.SessionInputBuffer.capacity.

Doc from org.apache.hc.core5.http.io.SessionInputBuffer.capacity.

Returns total capacity of the buffer

Returns:int

total capacity

Annotations
@Override
clearback to summary
public void clear()
fillBufferback to summary
public int fillBuffer(final InputStream inputStream) throws IOException
getMetricsback to summary
public HttpTransportMetrics getMetrics()

Implements org.apache.hc.core5.http.io.SessionInputBuffer.getMetrics.

Doc from org.apache.hc.core5.http.io.SessionInputBuffer.getMetrics.

Returns HttpTransportMetrics for this session buffer.

Returns:HttpTransportMetrics

transport metrics.

Annotations
@Override
handleDecodingResultback to summary
private int handleDecodingResult(final CoderResult result, final CharArrayBuffer charBuffer) throws IOException
hasBufferedDataback to summary
public boolean hasBufferedData()
lengthback to summary
public int length()

Implements org.apache.hc.core5.http.io.SessionInputBuffer.length.

Doc from org.apache.hc.core5.http.io.SessionInputBuffer.length.

Returns length data stored in the buffer

Returns:int

data length

Annotations
@Override
lineFromLineBufferback to summary
private int lineFromLineBuffer(final CharArrayBuffer charBuffer) throws IOException

Reads a complete line of characters up to a line delimiter from this session buffer. The line delimiter itself is discarded. If no char is available because the end of the stream has been reached, null is returned. This method blocks until input data is available, end of file is detected, or an exception is thrown.

This method treats a lone LF as a valid line delimiters in addition to CR-LF required by the HTTP specification.

Returns:int

HTTP line as a string

Exceptions
IOException:
if an I/O error occurs.
lineFromReadBufferback to summary
private int lineFromReadBuffer(final CharArrayBuffer charbuffer, final int position) throws IOException
readback to summary
public int read(final InputStream inputStream) throws IOException

Implements org.apache.hc.core5.http.io.SessionInputBuffer.read.

Doc from org.apache.hc.core5.http.io.SessionInputBuffer.read.

Reads the next byte of data from this session buffer. The value byte is returned as an int in the range 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.

Parameters
inputStream:InputStream

Input stream

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(final byte[] b, final int off, final int len, final InputStream inputStream) throws IOException

Implements org.apache.hc.core5.http.io.SessionInputBuffer.read.

Doc from org.apache.hc.core5.http.io.SessionInputBuffer.read.

Reads up to len bytes of data from the session buffer into an array of bytes. An attempt is made to read as many as len 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, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

inputStream:InputStream

Input stream

Returns:int

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.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(final byte[] b, final InputStream inputStream) throws IOException

Implements org.apache.hc.core5.http.io.SessionInputBuffer.read.

Doc from org.apache.hc.core5.http.io.SessionInputBuffer.read.

Reads some number of bytes from the session buffer and stores them into the buffer array b. 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:byte[]

the buffer into which the data is read.

inputStream:InputStream

Input stream

Returns:int

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.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readLineback to summary
public int readLine(final CharArrayBuffer charBuffer, final InputStream inputStream) throws IOException

Implements org.apache.hc.core5.http.io.SessionInputBuffer.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.

This method treats a lone LF as a valid line delimiters in addition to CR-LF required by the HTTP specification.

Parameters
charBuffer:CharArrayBuffer

the line buffer, one line of characters upon return

inputStream:InputStream

Doc from org.apache.hc.core5.http.io.SessionInputBuffer.readLine.

Input stream

Returns:int

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.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.