org.freecompany.redline
Class ReadableChannelWrapper

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

public class ReadableChannelWrapper
extends ChannelWrapper
implements java.nio.channels.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  java.nio.channels.ReadableByteChannel channel
           
 
Fields inherited from class org.freecompany.redline.ChannelWrapper
consumers
 
Constructor Summary
ReadableChannelWrapper(java.nio.channels.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(java.nio.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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channel

protected java.nio.channels.ReadableByteChannel channel
Constructor Detail

ReadableChannelWrapper

public ReadableChannelWrapper(java.nio.channels.ReadableByteChannel channel)
Method Detail

read

public int read(java.nio.ByteBuffer buffer)
         throws java.io.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 java.nio.channels.ReadableByteChannel
Parameters:
buffer - the buffer to read into
Returns:
the number of bytes read from the underlying channel
Throws:
java.io.IOException - if an IO error occurrs

close

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

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface java.nio.channels.Channel
Overrides:
close in class ChannelWrapper
Throws:
java.io.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 java.nio.channels.Channel
Returns:
true if the channel is open, false if not


Copyright © 2011. All Rights Reserved.