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

public Class SessionInputBufferImpl

extends Object
implements SessionInputBuffer, BufferInfo
Class Inheritance
All Implemented Interfaces
org.apache.http.io.BufferInfo, org.apache.http.io.SessionInputBuffer
Imports
java.io.IOException, .InputStream, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.CharsetDecoder, .CoderResult, org.apache.http.MessageConstraintException, org.apache.http.config.MessageConstraints, org.apache.http.io.BufferInfo, .HttpTransportMetrics, .SessionInputBuffer, org.apache.http.protocol.HTTP, org.apache.http.util.Args, .Asserts, .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) and readLine() methods 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 MessageConstraints
private final CharsetDecoder
private InputStream
private final ByteArrayBuffer
private final HttpTransportMetricsImpl
private final int

Constructor Summary

AccessConstructor and Description
public
SessionInputBufferImpl(final HttpTransportMetricsImpl
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 MessageConstraints
Message constraints. If null MessageConstraints#DEFAULT will be used.
constraints
,
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 HttpTransportMetricsImpl metrics, 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.http.io.BufferInfo.available.

Returns available space in the buffer.
public void
bind(final InputStream inputStream)

public int
capacity()

Implements org.apache.http.io.BufferInfo.capacity.

Returns total capacity of the buffer
public void
public int
public HttpTransportMetrics
private int
handleDecodingResult(final CoderResult result, final CharArrayBuffer charbuffer, final ByteBuffer bbuf)

public boolean
public boolean
public boolean
isDataAvailable(final int
in milliseconds.
timeout
)

Implements org.apache.http.io.SessionInputBuffer.isDataAvailable.

Blocks until some data becomes available in the session buffer or the given timeout period in milliseconds elapses.
public int
length()

Implements org.apache.http.io.BufferInfo.length.

Return 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()

Implements org.apache.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
)

Implements org.apache.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
)

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

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

Returns:

one line of characters
readLine
(final CharArrayBuffer
the line buffer.
charbuffer
)

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

Reads a complete line of characters up to a line delimiter from this session buffer into the given line buffer.
public String
readLine()

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

Reads a complete line of characters up to a line delimiter from this session buffer.
private int
streamRead(final byte[] b, final int off, final int len)

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
constraintsback to summary
private final MessageConstraints constraints
decoderback to summary
private final CharsetDecoder decoder
inStreamback to summary
private InputStream inStream
lineBufferback to summary
private final ByteArrayBuffer lineBuffer
metricsback to summary
private final HttpTransportMetricsImpl metrics
minChunkLimitback to summary
private final int minChunkLimit

Constructor Detail

SessionInputBufferImplback to summary
public SessionInputBufferImpl(final HttpTransportMetricsImpl metrics, final int bufferSize, final int minChunkLimit, final MessageConstraints constraints, final CharsetDecoder charDecoder)

Creates new instance of SessionInputBufferImpl.

Parameters
metrics:HttpTransportMetricsImpl

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.

constraints:MessageConstraints

Message constraints. If null MessageConstraints#DEFAULT will be used.

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 HttpTransportMetricsImpl metrics, 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.http.io.BufferInfo.available.

Doc from org.apache.http.io.BufferInfo.available.

Returns available space in the buffer.

Returns:int

available space.

Annotations
@Override
bindback to summary
public void bind(final InputStream inputStream)
capacityback to summary
public int capacity()

Implements org.apache.http.io.BufferInfo.capacity.

Doc from org.apache.http.io.BufferInfo.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() throws IOException
getMetricsback to summary
public HttpTransportMetrics getMetrics()

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

Doc from org.apache.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, final ByteBuffer bbuf) throws IOException
hasBufferedDataback to summary
public boolean hasBufferedData()
isBoundback to summary
public boolean isBound()
isDataAvailableback to summary
public boolean isDataAvailable(final int timeout) throws IOException

Implements org.apache.http.io.SessionInputBuffer.isDataAvailable.

Doc from org.apache.http.io.SessionInputBuffer.isDataAvailable.

Blocks until some data becomes available in the session buffer or the given timeout period in milliseconds elapses. If the timeout value is 0 this method blocks indefinitely.

Parameters
timeout:int

in milliseconds.

Returns:boolean

true if some data is available in the session buffer or false otherwise.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
lengthback to summary
public int length()

Implements org.apache.http.io.BufferInfo.length.

Doc from org.apache.http.io.BufferInfo.length.

Return 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() throws IOException

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

Doc from org.apache.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.

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) throws IOException

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

Doc from org.apache.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.

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) throws IOException

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

Doc from org.apache.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.

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) throws IOException

Implements org.apache.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.

Returns:int

one line of characters

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readLineback to summary
public String readLine() throws IOException

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

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

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.

The choice of a char encoding and line delimiter sequence is up to the specific implementations of this interface.

Returns:String

HTTP line as a string

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
streamReadback to summary
private int streamRead(final byte[] b, final int off, final int len) throws IOException