org.apache.http.impl.io
Class SessionInputBufferImpl

java.lang.Object
  extended by org.apache.http.impl.io.SessionInputBufferImpl
All Implemented Interfaces:
BufferInfo, org.apache.http.io.SessionInputBuffer

@NotThreadSafe
public class SessionInputBufferImpl
extends java.lang.Object
implements org.apache.http.io.SessionInputBuffer, BufferInfo

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

Constructor Summary
SessionInputBufferImpl(org.apache.http.impl.io.HttpTransportMetricsImpl metrics, int buffersize)
           
SessionInputBufferImpl(org.apache.http.impl.io.HttpTransportMetricsImpl metrics, int buffersize, int minChunkLimit, MessageConstraints constraints, java.nio.charset.CharsetDecoder chardecoder)
          Creates new instance of SessionInputBufferImpl.
 
Method Summary
 int available()
          Returns available space in the buffer.
 void bind(java.io.InputStream instream)
           
 int capacity()
          Returns total capacity of the buffer
 void clear()
           
 int fillBuffer()
           
 org.apache.http.io.HttpTransportMetrics getMetrics()
           
 boolean hasBufferedData()
           
 boolean isBound()
           
 boolean isDataAvailable(int timeout)
           
 int length()
          Return length data stored in the buffer
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 java.lang.String readLine()
           
 int readLine(org.apache.http.util.CharArrayBuffer charbuffer)
          Reads a complete line of characters up to a line delimiter from this session buffer into the given line buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionInputBufferImpl

public SessionInputBufferImpl(org.apache.http.impl.io.HttpTransportMetricsImpl metrics,
                              int buffersize,
                              int minChunkLimit,
                              MessageConstraints constraints,
                              java.nio.charset.CharsetDecoder chardecoder)
Creates new instance of SessionInputBufferImpl.

Parameters:
metrics - HTTP transport metrics.
buffersize - buffer size. Must be a positive number.
minChunkLimit - 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 - Message constraints. If null MessageConstraints.DEFAULT will be used.
chardecoder - chardecoder to be used for decoding HTTP protocol elements. If null simple type cast will be used for byte to char conversion.

SessionInputBufferImpl

public SessionInputBufferImpl(org.apache.http.impl.io.HttpTransportMetricsImpl metrics,
                              int buffersize)
Method Detail

bind

public void bind(java.io.InputStream instream)

isBound

public boolean isBound()

capacity

public int capacity()
Description copied from interface: BufferInfo
Returns total capacity of the buffer

Specified by:
capacity in interface BufferInfo
Returns:
total capacity

length

public int length()
Description copied from interface: BufferInfo
Return length data stored in the buffer

Specified by:
length in interface BufferInfo
Returns:
data length

available

public int available()
Description copied from interface: BufferInfo
Returns available space in the buffer.

Specified by:
available in interface BufferInfo
Returns:
available space.

fillBuffer

public int fillBuffer()
               throws java.io.IOException
Throws:
java.io.IOException

hasBufferedData

public boolean hasBufferedData()

clear

public void clear()

read

public int read()
         throws java.io.IOException
Specified by:
read in interface org.apache.http.io.SessionInputBuffer
Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Specified by:
read in interface org.apache.http.io.SessionInputBuffer
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
Specified by:
read in interface org.apache.http.io.SessionInputBuffer
Throws:
java.io.IOException

readLine

public int readLine(org.apache.http.util.CharArrayBuffer charbuffer)
             throws java.io.IOException
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.

Specified by:
readLine in interface org.apache.http.io.SessionInputBuffer
Parameters:
charbuffer - the line buffer.
Returns:
one line of characters
Throws:
java.io.IOException - if an I/O error occurs.

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Specified by:
readLine in interface org.apache.http.io.SessionInputBuffer
Throws:
java.io.IOException

isDataAvailable

public boolean isDataAvailable(int timeout)
                        throws java.io.IOException
Specified by:
isDataAvailable in interface org.apache.http.io.SessionInputBuffer
Throws:
java.io.IOException

getMetrics

public org.apache.http.io.HttpTransportMetrics getMetrics()
Specified by:
getMetrics in interface org.apache.http.io.SessionInputBuffer