org.freecompany.redline
Class ReadableChannelWrapper

java.lang.Object
  extended by org.freecompany.redline.ChannelWrapper
      extended by org.freecompany.redline.ReadableChannelWrapper
All Implemented Interfaces:
Closeable, Channel, ReadableByteChannel

public class ReadableChannelWrapper
extends ChannelWrapper
implements ReadableByteChannel

Wrapper for observing data read from a NIO channel. This wrapper is used for operations that must be notified of incoming IO data.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.freecompany.redline.ChannelWrapper
ChannelWrapper.Consumer<T>, ChannelWrapper.Key<T>
 
Field Summary
protected  ReadableByteChannel channel
           
 
Fields inherited from class org.freecompany.redline.ChannelWrapper
consumers
 
Constructor Summary
ReadableChannelWrapper(ReadableByteChannel channel)
           
 
Method Summary
 void close()
          Close the underlying read channel and complete any operations in the consumer.
 boolean isOpen()
          Boolean flag indicating whether the channel is open or closed.
 int read(ByteBuffer buffer)
          Reads data from the channel and passes it to the consumer.
 
Methods inherited from class org.freecompany.redline.ChannelWrapper
finish, start, start, start, start, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channel

protected ReadableByteChannel channel
Constructor Detail

ReadableChannelWrapper

public ReadableChannelWrapper(ReadableByteChannel channel)
Method Detail

read

public int read(ByteBuffer buffer)
         throws IOException
Reads data from the channel and passes it to the consumer. This method does not mutate the acutal data in the provided buffer, but makes it's own copy to pass to the consumer.

Specified by:
read in interface ReadableByteChannel
Parameters:
buffer - the buffer to read into
Returns:
the number of bytes read from the underlying channel
Throws:
IOException - if an IO error occurrs

close

public void close()
           throws IOException
Close the underlying read channel and complete any operations in the consumer.

Specified by:
close in interface Closeable
Specified by:
close in interface Channel
Overrides:
close in class ChannelWrapper
Throws:
IOException - if an IO error occurrs

isOpen

public boolean isOpen()
Boolean flag indicating whether the channel is open or closed.

Specified by:
isOpen in interface Channel
Returns:
true if the channel is open, false if not


Copyright © 2014. All Rights Reserved.