net.officefloor.plugin.stream.impl
Class BufferStreamImpl

java.lang.Object
  extended by net.officefloor.plugin.stream.impl.BufferStreamImpl
All Implemented Interfaces:
BufferStream

public class BufferStreamImpl
extends Object
implements BufferStream

BufferStream implementation.

Author:
Daniel Sagenschneider

Field Summary
 
Fields inherited from interface net.officefloor.plugin.stream.BufferStream
END_OF_STREAM
 
Constructor Summary
BufferStreamImpl(BufferSquirtFactory squirtFactory)
          Initiate.
BufferStreamImpl(ByteBuffer data)
          Initiate to input data.
 
Method Summary
 void append(BufferSquirt squirt)
           Appends the BufferSquirt to the BufferStream.
 void append(ByteBuffer buffer)
           Appends the ByteBuffer to the BufferStream.
 long available()
          Provides an accurate number of bytes available in the BufferStream.
 void closeInput()
           Closes the input to the BufferStream and releases the resources.
 void closeOutput()
           Closes the output to the BufferStream and releases the resources.
 InputStream getBrowseStream()
           Obtains an InputStream that allows browsing the contents of the BufferStream without changing the BufferStream markers.
 InputBufferStream getInputBufferStream()
          Obtains the InputBufferStream for this BufferStream.
 OutputBufferStream getOutputBufferStream()
          Obtains the OutputBufferStream for this 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.
 void write(BufferPopulator populator)
          Writes content to a ByteBuffer of the BufferStream.
 void write(byte[] bytes)
          Writes the bytes to the BufferStream.
 void write(byte[] bytes, int offset, int length)
          Writes the bytes to the BufferStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferStreamImpl

public BufferStreamImpl(BufferSquirtFactory squirtFactory)
Initiate.

Parameters:
squirtFactory - BufferSquirtFactory.

BufferStreamImpl

public BufferStreamImpl(ByteBuffer data)
                 throws IOException
Initiate to input data.

Parameters:
data - Data.
Throws:
IOException - If fails to initiate.
Method Detail

getOutputBufferStream

public OutputBufferStream getOutputBufferStream()
Description copied from interface: BufferStream
Obtains the OutputBufferStream for this BufferStream.

Specified by:
getOutputBufferStream in interface BufferStream
Returns:
OutputBufferStream.

write

public void write(byte[] bytes)
           throws IOException
Description copied from interface: BufferStream
Writes the bytes to the BufferStream.

Specified by:
write in interface BufferStream
Parameters:
bytes - Bytes to be written to the BufferStream.
Throws:
IOException - If fails to write the bytes.

write

public void write(byte[] bytes,
                  int offset,
                  int length)
           throws IOException
Description copied from interface: BufferStream
Writes the bytes to the BufferStream.

Specified by:
write in interface BufferStream
Parameters:
bytes - Bytes to be written to the BufferStream.
offset - Offset into the bytes to start obtain bytes to write.
length - Number of bytes to write.
Throws:
IOException - If fails to write the bytes.

write

public void write(BufferPopulator populator)
           throws IOException
Description copied from interface: BufferStream
Writes content to a ByteBuffer of the BufferStream.

Specified by:
write in interface BufferStream
Parameters:
populator - BufferPopulator to write data to the ByteBuffer.
Throws:
IOException - If fails to write data to ByteBuffer.

append

public void append(ByteBuffer buffer)
            throws IOException
Description copied from interface: BufferStream

Appends the ByteBuffer to the BufferStream.

The ByteBuffer is used directly by the BufferStream and must not be changed until the BufferStream is no longer being used. This should only be used when the ByteBuffer never changes (contains static information).

Use BufferStream.append(BufferSquirt) over this method to know when the ByteBuffer can be modified again.

Specified by:
append in interface BufferStream
Parameters:
buffer - ByteBuffer ready to be read from.
Throws:
IOException - If fails to append to the BufferStream.

append

public void append(BufferSquirt squirt)
            throws IOException
Description copied from interface: BufferStream

Appends the BufferSquirt to the BufferStream.

BufferSquirt.close() is invoked when the BufferStream no longer requires the BufferSquirt.

Specified by:
append in interface BufferStream
Parameters:
squirt - BufferSquirt to append to the BufferStream.
Throws:
IOException - If fails to append to the BufferStream.

closeOutput

public void closeOutput()
Description copied from interface: BufferStream

Closes the output to the BufferStream and releases the resources.

Further output will result in an IOException.

Specified by:
closeOutput in interface BufferStream

getInputBufferStream

public InputBufferStream getInputBufferStream()
Description copied from interface: BufferStream
Obtains the InputBufferStream for this BufferStream.

Specified by:
getInputBufferStream in interface BufferStream
Returns:
InputBufferStream.

getBrowseStream

public InputStream getBrowseStream()
Description copied from interface: BufferStream

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.

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

read

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

Specified by:
read in interface BufferStream
Parameters:
readBuffer - Buffer to be loaded with the BufferStream content.
Returns:
Number of bytes loaded into the input buffer from the BufferStream. Return of BufferStream.END_OF_STREAM indicates end of stream with no bytes loaded to buffer.
Throws:
IOException - If failure 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: BufferStream
Reads the content from the BufferStream into the input buffer returning the number of bytes loaded.

Specified by:
read in interface BufferStream
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: BufferStream
Reads and processes the contents of a ByteBuffer from the BufferStream.

Specified by:
read in interface BufferStream
Parameters:
processor - BufferProcessor to process the data of the ByteBuffer.
Returns:
Number of bytes in the ByteBuffer provided to the BufferProcessor to process. Return of BufferStream.END_OF_STREAM indicates end of stream with the BufferProcessor not invoked.
Throws:
IOException - If fails to read input. Typically this will be because the input is closed.

read

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

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 BufferStream
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: BufferStream

Reads data from this BufferStream to the OutputBufferStream.

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

Specified by:
read in interface BufferStream
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: BufferStream
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 BufferStream
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: BufferStream
Provides an accurate number of bytes available in the BufferStream.

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

closeInput

public void closeInput()
Description copied from interface: BufferStream

Closes the input to the BufferStream and releases the resources.

Further output will be ignored.

Specified by:
closeInput in interface BufferStream


Copyright © 2005-2011. All Rights Reserved.