org.apache.http.impl.nio.reactor
Class SessionInputBufferImpl

java.lang.Object
  extended by org.apache.http.nio.util.ExpandableBuffer
      extended by org.apache.http.impl.nio.reactor.SessionInputBufferImpl
All Implemented Interfaces:
SessionInputBuffer, BufferInfo

public class SessionInputBufferImpl
extends ExpandableBuffer
implements SessionInputBuffer

Default implementation of SessionInputBuffer based on the ExpandableBuffer class.

Since:
4.0

Field Summary
 
Fields inherited from class org.apache.http.nio.util.ExpandableBuffer
buffer, INPUT_MODE, OUTPUT_MODE
 
Constructor Summary
SessionInputBufferImpl(int bufferSize)
          Creates SessionInputBufferImpl instance.
SessionInputBufferImpl(int bufferSize, int lineBufferSize)
          Creates SessionInputBufferImpl instance.
SessionInputBufferImpl(int bufferSize, int lineBufferSize, ByteBufferAllocator allocator, HttpParams params)
          Deprecated. (4.3) use SessionInputBufferImpl(int, int, CharsetDecoder, ByteBufferAllocator)
SessionInputBufferImpl(int bufferSize, int lineBufferSize, Charset charset)
          Creates SessionInputBufferImpl instance.
SessionInputBufferImpl(int bufferSize, int lineBufferSize, CharsetDecoder charDecoder, ByteBufferAllocator allocator)
          Creates SessionInputBufferImpl instance.
SessionInputBufferImpl(int bufferSize, int lineBufferSize, HttpParams params)
          Deprecated. (4.3) use SessionInputBufferImpl(int, int, Charset)
SessionInputBufferImpl(int bufferSize, int lineBufferSize, MessageConstraints constraints, Charset charset)
          Creates SessionInputBufferImpl instance.
SessionInputBufferImpl(int bufferSize, int lineBufferSize, MessageConstraints constraints, CharsetDecoder charDecoder, ByteBufferAllocator allocator)
          Creates SessionInputBufferImpl instance.
 
Method Summary
 int fill(ReadableByteChannel channel)
          Makes an attempt to fill the buffer with data from the given ReadableByteChannel.
 int read()
          Reads one byte from the buffer.
 int read(ByteBuffer dst)
          Reads a sequence of bytes from this buffer into the destination buffer.
 int read(ByteBuffer dst, int maxLen)
          Reads a sequence of bytes from this buffer into the destination buffer, up to the given maximum limit.
 int read(WritableByteChannel dst)
          Reads a sequence of bytes from this buffer into the destination channel.
 int read(WritableByteChannel dst, int maxLen)
          Reads a sequence of bytes from this buffer into the destination channel, up to the given maximum limit.
 String readLine(boolean endOfStream)
          Attempts to transfer a complete line of characters up to a line delimiter from this buffer to a newly created string.
 boolean readLine(CharArrayBuffer lineBuffer, boolean endOfStream)
          Attempts to transfer a complete line of characters up to a line delimiter from this buffer to the destination buffer.
 
Methods inherited from class org.apache.http.nio.util.ExpandableBuffer
available, capacity, clear, ensureCapacity, expand, getMode, hasData, length, setInputMode, setOutputMode, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.http.nio.reactor.SessionInputBuffer
hasData, length
 

Constructor Detail

SessionInputBufferImpl

public SessionInputBufferImpl(int bufferSize,
                              int lineBufferSize,
                              MessageConstraints constraints,
                              CharsetDecoder charDecoder,
                              ByteBufferAllocator allocator)
Creates SessionInputBufferImpl instance.

Parameters:
bufferSize - input buffer size.
lineBufferSize - buffer size for line operations. Has effect only if charDecoder is not null.
charDecoder - CharDecoder to be used for decoding HTTP protocol elements. If null simple type cast will be used for byte to char conversion.
constraints - Message constraints. If null MessageConstraints.DEFAULT will be used.
allocator - memory allocator. If null HeapByteBufferAllocator.INSTANCE will be used.
Since:
4.4

SessionInputBufferImpl

public SessionInputBufferImpl(int bufferSize,
                              int lineBufferSize,
                              CharsetDecoder charDecoder,
                              ByteBufferAllocator allocator)
Creates SessionInputBufferImpl instance.

Parameters:
bufferSize - input buffer size.
lineBufferSize - buffer size for line operations. Has effect only if charDecoder is not null.
charDecoder - CharDecoder to be used for decoding HTTP protocol elements. If null simple type cast will be used for byte to char conversion.
allocator - memory allocator. If null HeapByteBufferAllocator.INSTANCE will be used.
Since:
4.3

SessionInputBufferImpl

@Deprecated
public SessionInputBufferImpl(int bufferSize,
                                         int lineBufferSize,
                                         ByteBufferAllocator allocator,
                                         HttpParams params)
Deprecated. (4.3) use SessionInputBufferImpl(int, int, CharsetDecoder, ByteBufferAllocator)


SessionInputBufferImpl

@Deprecated
public SessionInputBufferImpl(int bufferSize,
                                         int lineBufferSize,
                                         HttpParams params)
Deprecated. (4.3) use SessionInputBufferImpl(int, int, Charset)


SessionInputBufferImpl

public SessionInputBufferImpl(int bufferSize,
                              int lineBufferSize,
                              Charset charset)
Creates SessionInputBufferImpl instance.

Parameters:
bufferSize - input buffer size.
lineBufferSize - buffer size for line operations. Has effect only if charset is not null.
charset - Charset to be used for decoding HTTP protocol elements. If null simple type cast will be used for byte to char conversion.
Since:
4.3

SessionInputBufferImpl

public SessionInputBufferImpl(int bufferSize,
                              int lineBufferSize,
                              MessageConstraints constraints,
                              Charset charset)
Creates SessionInputBufferImpl instance.

Parameters:
bufferSize - input buffer size.
lineBufferSize - buffer size for line operations. Has effect only if charset is not null.
charset - Charset to be used for decoding HTTP protocol elements. If null simple type cast will be used for byte to char conversion.
constraints - Message constraints. If null MessageConstraints.DEFAULT will be used.
Since:
4.3

SessionInputBufferImpl

public SessionInputBufferImpl(int bufferSize,
                              int lineBufferSize)
Creates SessionInputBufferImpl instance.

Parameters:
bufferSize - input buffer size.
lineBufferSize - buffer size for line operations.
Since:
4.3

SessionInputBufferImpl

public SessionInputBufferImpl(int bufferSize)
Creates SessionInputBufferImpl instance.

Parameters:
bufferSize - input buffer size.
Since:
4.3
Method Detail

fill

public int fill(ReadableByteChannel channel)
         throws IOException
Description copied from interface: SessionInputBuffer
Makes an attempt to fill the buffer with data from the given ReadableByteChannel.

Specified by:
fill in interface SessionInputBuffer
Parameters:
channel - the source channel
Returns:
The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream.
Throws:
IOException - in case of an I/O error.

read

public int read()
Description copied from interface: SessionInputBuffer
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.

Specified by:
read in interface SessionInputBuffer
Returns:
one byte

read

public int read(ByteBuffer dst,
                int maxLen)
Description copied from interface: SessionInputBuffer
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 than maxLen value.

Specified by:
read in interface SessionInputBuffer
Parameters:
dst - the destination buffer.
maxLen - the maximum number of bytes to be read.
Returns:
The number of bytes read, possibly zero.

read

public int read(ByteBuffer dst)
Description copied from interface: SessionInputBuffer
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.

Specified by:
read in interface SessionInputBuffer
Parameters:
dst - the destination buffer.
Returns:
The number of bytes read, possibly zero.

read

public int read(WritableByteChannel dst,
                int maxLen)
         throws IOException
Description copied from interface: SessionInputBuffer
Reads 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 than maxLen value.

Specified by:
read in interface SessionInputBuffer
Parameters:
dst - the destination channel.
maxLen - the maximum number of bytes to be read.
Returns:
The number of bytes read, possibly zero.
Throws:
IOException - in case of an I/O error.

read

public int read(WritableByteChannel dst)
         throws IOException
Description copied from interface: SessionInputBuffer
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.

Specified by:
read in interface SessionInputBuffer
Parameters:
dst - the destination channel.
Returns:
The number of bytes read, possibly zero.
Throws:
IOException - in case of an I/O error.

readLine

public boolean readLine(CharArrayBuffer lineBuffer,
                        boolean endOfStream)
                 throws CharacterCodingException
Description copied from interface: SessionInputBuffer
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 returns true. The line delimiter itself is discarded. If a complete line is not available in the buffer, this method returns false without transferring anything to the destination buffer. If endOfStream parameter is set to true this 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.

Specified by:
readLine in interface SessionInputBuffer
Parameters:
lineBuffer - the destination buffer.
endOfStream - end of stream flag
Returns:
true if a sequence of chars representing a complete line has been transferred to the destination buffer, false otherwise.
Throws:
CharacterCodingException - in case a character encoding or decoding error occurs.

readLine

public String readLine(boolean endOfStream)
                throws CharacterCodingException
Description copied from interface: SessionInputBuffer
Attempts 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 returns null. If endOfStream parameter is set to true this 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.

Specified by:
readLine in interface SessionInputBuffer
Parameters:
endOfStream - end of stream flag
Returns:
a string representing a complete line, if available. null otherwise.
Throws:
CharacterCodingException - in case a character encoding or decoding error occurs.


Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.