net.officefloor.plugin.stream.impl
Class InputBufferStreamImpl

java.lang.Object
  extended by net.officefloor.plugin.stream.impl.InputBufferStreamImpl
All Implemented Interfaces:
InputBufferStream

public class InputBufferStreamImpl
extends Object
implements InputBufferStream

InputBufferStream implementation.

Author:
Daniel Sagenschneider

Constructor Summary
InputBufferStreamImpl(BufferStream bufferStream)
          Initiate.
 
Method Summary
 long available()
          Provides an accurate number of bytes available in the BufferStream.
 void close()
          Closes the stream releasing resources.
 InputStream getBrowseStream()
           Obtains an InputStream that allows browsing the contents of the BufferStream without changing the BufferStream markers.
 InputStream getInputStream()
           Obtains the InputStream that reads the contents of the BufferStream.
 int read(BufferProcessor processor)
           Reads and processes the contents of a ByteBuffer from the BufferStream.
 int read(byte[] readBuffer)
          Reads the content from the BufferStream into the input buffer returning the number of bytes loaded.
 int read(byte[] readBuffer, int offset, int length)
          Reads the content from the BufferStream into the input buffer returning the number of bytes loaded.
 int read(int numberOfBytes, GatheringBufferProcessor processor)
           Processes a batch number of ByteBuffer instances so that the available data in the ByteBuffer instances is greater than or equal to the number of bytes specified.
 int read(int numberOfBytes, OutputBufferStream outputBufferStream)
           Reads data from this BufferStream to the OutputBufferStream.
 long skip(long numberOfBytes)
          Skips the input number of bytes in the BufferStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputBufferStreamImpl

public InputBufferStreamImpl(BufferStream bufferStream)
Initiate.

Parameters:
bufferStream - BufferStream.
Method Detail

getInputStream

public InputStream getInputStream()
Description copied from interface: InputBufferStream

Obtains the InputStream that reads the contents of the BufferStream.

As the BufferStream is non-blocking any attempt to read data when none is available will result in an IOException. InputStream.available() is implemented to provide an accurate size of available bytes.

Specified by:
getInputStream in interface InputBufferStream
Returns:
InputStream to read from the BufferStream.

getBrowseStream

public InputStream getBrowseStream()
Description copied from interface: InputBufferStream

Obtains an InputStream that allows browsing the contents of the BufferStream without changing the BufferStream markers.

Once the available data has been browsed, further reads will return BufferStream.END_OF_STREAM indicating end of stream of available data. It is therefore optional for InputStream.available() to provide the available bytes (unlike InputBufferStream.getInputStream().

Specified by:
getBrowseStream in interface InputBufferStream
Returns:
InputStream to browse the BufferStream.

read

public int read(byte[] readBuffer)
         throws IOException
Description copied from interface: InputBufferStream
Reads the content from the BufferStream into the input buffer returning the number of bytes loaded.

Specified by:
read in interface InputBufferStream
Parameters:
readBuffer - Buffer to load BufferStream content.
Returns:
Number of bytes loaded into the buffer from the BufferStream. Return of BufferStream.END_OF_STREAM indicates end of stream with no bytes loaded to buffer.
Throws:
IOException - If fails to read input. Typically this will be because the input is closed.

read

public int read(byte[] readBuffer,
                int offset,
                int length)
         throws IOException
Description copied from interface: InputBufferStream
Reads the content from the BufferStream into the input buffer returning the number of bytes loaded.

Specified by:
read in interface InputBufferStream
Parameters:
readBuffer - Buffer to load BufferStream content.
offset - Offset of the input read buffer to start loading data from the BufferStream.
length - Maximum number of bytes to be loaded.
Returns:
Number of bytes loaded into the buffer from the BufferStream. Return of BufferStream.END_OF_STREAM indicates end of stream with no bytes loaded to buffer.
Throws:
IOException - If fails to read input. Typically this will be because the input is closed.

read

public int read(BufferProcessor processor)
         throws IOException
Description copied from interface: InputBufferStream

Reads and processes the contents of a ByteBuffer from the BufferStream.

As ByteBuffer instances may be stored in varying sizes within the BufferStream and data already consumed from them, the provided ByteBuffer will have a variable number of bytes remaining.

Specified by:
read in interface InputBufferStream
Parameters:
processor - BufferProcessor to process the data of the ByteBuffer.
Returns:
Number of bytes in the ByteBuffer provided to the BufferProcessor that were processed (read). Return of BufferStream.END_OF_STREAM indicates end of stream.
Throws:
IOException - If fails to read input. Typically this will be because the input is closed.
See Also:
InputBufferStream.read(int, GatheringBufferProcessor)

read

public int read(int numberOfBytes,
                GatheringBufferProcessor processor)
         throws IOException
Description copied from interface: InputBufferStream

Processes a batch number of ByteBuffer instances so that the available data in the ByteBuffer instances is greater than or equal to the number of bytes specified.

Should the number of bytes be greater than the available, all ByteBuffer instances are provided to the GatheringBufferProcessor. In this case the provided data will be less than the number of bytes specified.

Typically this will be used by gather operations such as with the GatheringByteChannel and SSLEngine.

Specified by:
read in interface InputBufferStream
Parameters:
numberOfBytes - Number of bytes to be processed from this InputBufferStream.
processor - GatheringBufferProcessor.
Returns:
Number of bytes read by the GatheringBufferProcessor.
Throws:
IOException - If fails to read input. Typically this will be because the input is closed.

read

public int read(int numberOfBytes,
                OutputBufferStream outputBufferStream)
         throws IOException
Description copied from interface: InputBufferStream

Reads data from this BufferStream to the OutputBufferStream.

Only available bytes are read to the OutputBufferStream and therefore the requested number of bytes may not be read. The return provides the number of bytes read.

Specified by:
read in interface InputBufferStream
Parameters:
numberOfBytes - Number of bytes to read into the OutputBufferStream.
outputBufferStream - OutputBufferStream to receive the data.
Returns:
Number of bytes transferred to the OutputBufferStream. Return of BufferStream.END_OF_STREAM indicates end of stream.
Throws:
IOException - If fails to read input. Typically this will be because the input is closed.

skip

public long skip(long numberOfBytes)
          throws IOException
Description copied from interface: InputBufferStream
Skips the input number of bytes in the BufferStream. As there may not be the available bytes to skip in the BufferStream, this method returns the actual number of bytes skipped from the available bytes.

Specified by:
skip in interface InputBufferStream
Parameters:
numberOfBytes - Maximum number of bytes to skip.
Returns:
Number of available bytes skipped in the BufferStream. Return of BufferStream.END_OF_STREAM indicates end of stream with no bytes skipped.
Throws:
IOException - If fails to skip the bytes. Typically this will be because the input is closed.

available

public long available()
Description copied from interface: InputBufferStream
Provides an accurate number of bytes available in the BufferStream.

Specified by:
available in interface InputBufferStream
Returns:
Number of bytes available in the BufferStream. Return of BufferStream.END_OF_STREAM indicates end of stream.

close

public void close()
Description copied from interface: InputBufferStream
Closes the stream releasing resources.

Specified by:
close in interface InputBufferStream


Copyright © 2005-2011. All Rights Reserved.