org.apache.http.nio.util
Class SharedInputBuffer

java.lang.Object
  extended by org.apache.http.nio.util.ExpandableBuffer
      extended by org.apache.http.nio.util.SharedInputBuffer
All Implemented Interfaces:
BufferInfo, ContentInputBuffer

@ThreadSafe
public class SharedInputBuffer
extends ExpandableBuffer
implements ContentInputBuffer

Implementation of the ContentInputBuffer interface that can be shared by multiple threads, usually the I/O dispatch of an I/O reactor and a worker thread.

The I/O dispatch thread is expect to transfer data from ContentDecoder to the buffer by calling consumeContent(ContentDecoder).

The worker thread is expected to read the data from the buffer by calling read() or read(byte[], int, int) methods.

In case of an abnormal situation or when no longer needed the buffer must be shut down using shutdown() method.

Since:
4.0

Field Summary
 
Fields inherited from class org.apache.http.nio.util.ExpandableBuffer
buffer, INPUT_MODE, OUTPUT_MODE
 
Constructor Summary
SharedInputBuffer(int buffersize)
           
SharedInputBuffer(int buffersize, ByteBufferAllocator allocator)
           
SharedInputBuffer(int buffersize, IOControl ioctrl, ByteBufferAllocator allocator)
          Deprecated. (4.3) use SharedInputBuffer(int, ByteBufferAllocator)
 
Method Summary
 int available()
          Returns available capacity of this buffer.
 int capacity()
          Returns the total capacity of this buffer.
 void close()
           
 int consumeContent(ContentDecoder decoder)
          Deprecated. (4.3) use consumeContent(ContentDecoder, IOControl)
 int consumeContent(ContentDecoder decoder, IOControl ioctrl)
           
 boolean hasData()
          Determines if the buffer contains data.
protected  boolean isEndOfStream()
           
protected  boolean isShutdown()
           
 int length()
          Returns the length of this buffer.
 int read()
          Reads one byte from this buffer.
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from this buffer into an array of bytes.
 void reset()
          Resets the buffer by clearing its state and stored content.
 void shutdown()
           
protected  void waitForData()
           
 
Methods inherited from class org.apache.http.nio.util.ExpandableBuffer
clear, ensureCapacity, expand, getMode, setInputMode, setOutputMode, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SharedInputBuffer

@Deprecated
public SharedInputBuffer(int buffersize,
                                    IOControl ioctrl,
                                    ByteBufferAllocator allocator)
Deprecated. (4.3) use SharedInputBuffer(int, ByteBufferAllocator)


SharedInputBuffer

public SharedInputBuffer(int buffersize,
                         ByteBufferAllocator allocator)
Since:
4.3

SharedInputBuffer

public SharedInputBuffer(int buffersize)
Since:
4.3
Method Detail

reset

public void reset()
Description copied from interface: ContentInputBuffer
Resets the buffer by clearing its state and stored content.

Specified by:
reset in interface ContentInputBuffer

consumeContent

@Deprecated
public int consumeContent(ContentDecoder decoder)
                   throws IOException
Deprecated. (4.3) use consumeContent(ContentDecoder, IOControl)

Description copied from interface: ContentInputBuffer
Reads content from the given ContentDecoder and stores it in this buffer.

Specified by:
consumeContent in interface ContentInputBuffer
Parameters:
decoder - the content decoder.
Returns:
number of bytes read.
Throws:
IOException - in case of an I/O error.

consumeContent

public int consumeContent(ContentDecoder decoder,
                          IOControl ioctrl)
                   throws IOException
Throws:
IOException
Since:
4.3

hasData

public boolean hasData()
Description copied from class: ExpandableBuffer
Determines if the buffer contains data.

Overrides:
hasData in class ExpandableBuffer
Returns:
true if there is data in the buffer, false otherwise.

available

public int available()
Description copied from class: ExpandableBuffer
Returns available capacity of this buffer.

Specified by:
available in interface BufferInfo
Overrides:
available in class ExpandableBuffer
Returns:
buffer length.

capacity

public int capacity()
Description copied from class: ExpandableBuffer
Returns the total capacity of this buffer.

Specified by:
capacity in interface BufferInfo
Overrides:
capacity in class ExpandableBuffer
Returns:
total capacity.

length

public int length()
Description copied from class: ExpandableBuffer
Returns the length of this buffer.

Specified by:
length in interface BufferInfo
Overrides:
length in class ExpandableBuffer
Returns:
buffer length.

waitForData

protected void waitForData()
                    throws IOException
Throws:
IOException

close

public void close()

shutdown

public void shutdown()

isShutdown

protected boolean isShutdown()

isEndOfStream

protected boolean isEndOfStream()

read

public int read()
         throws IOException
Description copied from interface: ContentInputBuffer
Reads one byte from this 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. This method returns -1 if the end of content stream has been reached.

Specified by:
read in interface ContentInputBuffer
Returns:
one byte
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Description copied from interface: ContentInputBuffer
Reads up to len bytes of data from this buffer into an array of bytes. The exact number of bytes read depends how many bytes are stored in the buffer.

If off is negative, or len is negative, or off+len is greater than the length of the array b, this method can throw a runtime exception. The exact type of runtime exception thrown by this method depends on implementation. This method returns -1 if the end of content stream has been reached.

Specified by:
read in interface ContentInputBuffer
Parameters:
b - the buffer into which the data is read.
off - the start offset in array b at which the data is written.
len - the maximum number of bytes to read.
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

public int read(byte[] b)
         throws IOException
Throws:
IOException


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