messif.objects.nio
Class ChannelInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by messif.objects.nio.BufferInputStream
          extended by messif.objects.nio.ChannelInputStream
All Implemented Interfaces:
java.io.Closeable, BinaryInput
Direct Known Subclasses:
FileChannelInputStream

public class ChannelInputStream
extends BufferInputStream
implements BinaryInput

Buffered binary input stream.

Note that it is not safe to use several ChannelInputStreams over the same channel (even if synchronized). For file channels, the FileChannelInputStream can be used if you need this functionality. Use copy-pipes if you need it on other channel types.

If multiple threads use the same instance of this class, the access to the instance must be synchronized.

See Also:
ChannelOutputStream

Constructor Summary
ChannelInputStream(java.nio.channels.ReadableByteChannel readChannel, int bufferSize, boolean bufferDirect)
          Creates a new instance of BinaryInput.
 
Method Summary
protected  void read(java.nio.ByteBuffer buffer)
          Reads some data into the buffer.
 
Methods inherited from class messif.objects.nio.BufferInputStream
available, bufferedSize, getPosition, read, read, read, read, readInput, setPosition, skip
 
Methods inherited from class java.io.InputStream
close, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface messif.objects.nio.BinaryInput
readInput, skip
 

Constructor Detail

ChannelInputStream

public ChannelInputStream(java.nio.channels.ReadableByteChannel readChannel,
                          int bufferSize,
                          boolean bufferDirect)
Creates a new instance of BinaryInput.

Parameters:
readChannel - the channel used to read data
bufferSize - the size of the internal buffer used for flushing
bufferDirect - allocate the internal buffer as direct
Method Detail

read

protected void read(java.nio.ByteBuffer buffer)
             throws java.io.EOFException,
                    java.io.IOException
Description copied from class: BufferInputStream
Reads some data into the buffer. This method blocks until at least one byte is read or, if there are no more data, EOFException is thrown.

Overrides:
read in class BufferInputStream
Parameters:
buffer - the buffer into which to read additional data
Throws:
java.io.EOFException - if there are no more data available
java.io.IOException - if there was an error reading data