org.entityfs.support.io
Class ReadableByteBufferChannel

java.lang.Object
  extended by org.entityfs.support.io.ReadableByteBufferChannel
All Implemented Interfaces:
Closeable, Channel, ReadableByteChannel

public class ReadableByteBufferChannel
extends Object
implements ReadableByteChannel

This is a ReadableByteChannel that uses a ByteBuffer to read data from. It assumes exclusive access to the ByteBuffer.

Read operations will update the ByteBuffer's internal position.

Since:
1.0
Author:
Karl Gustafsson
In_jar:
entityfs-core

Field Summary
static int DEFAULT_TEMP_BUFFER_SIZE
           
 
Constructor Summary
ReadableByteBufferChannel(ByteBuffer buffer)
          Create a new ReadableByteBufferChannel.
ReadableByteBufferChannel(ByteBuffer buffer, int tempBufferSize)
          Create a new ReadableByteBufferChannel.
 
Method Summary
 void close()
           
 boolean isOpen()
           
 int read(ByteBuffer target)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TEMP_BUFFER_SIZE

public static final int DEFAULT_TEMP_BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

ReadableByteBufferChannel

public ReadableByteBufferChannel(ByteBuffer buffer,
                                 int tempBufferSize)
                          throws IllegalArgumentException
Create a new ReadableByteBufferChannel.

Parameters:
buffer - The buffer to read data from.
tempBufferSize - The size, in bytes, of the temporary buffer used when reading data from the buffer. It must be >= 1 byte.
Throws:
IllegalArgumentException - If the temporary buffer size is invalid.

ReadableByteBufferChannel

public ReadableByteBufferChannel(ByteBuffer buffer)
Create a new ReadableByteBufferChannel. The default size, 8192 bytes, will be used for the temporary buffer used when reading data.

Parameters:
buffer - The buffer to read data from.
Method Detail

read

public int read(ByteBuffer target)
         throws IOException
Specified by:
read in interface ReadableByteChannel
Throws:
IOException

isOpen

public boolean isOpen()
Specified by:
isOpen in interface Channel

close

public void close()
Specified by:
close in interface Closeable
Specified by:
close in interface Channel