com.trendrr.oss.networking
Class SocketChannelWrapper

java.lang.Object
  extended by com.trendrr.oss.networking.SocketChannelWrapper

public class SocketChannelWrapper
extends java.lang.Object

Author:
Dustin Norlander

Constructor Summary
SocketChannelWrapper(java.nio.channels.SocketChannel channel)
           
 
Method Summary
 void close()
          attempts to process the remaining callbacks, then closes the channel and cleans up any resources.
 void doRead()
          Attempts to read from the network, and process any callbacks.
 java.nio.channels.SocketChannel getChannel()
           
 java.util.Queue<java.nio.ByteBuffer> getWrites()
           
 boolean hasReads()
          returns true if any reads are waiting.
 boolean hasWrites()
          returns true if there are any writes waiting.
 boolean isClosed()
           
 byte[] readBytes(int numBytes)
           
 void readBytes(int numBytes, ByteReadCallback callback)
           
 java.lang.String readUntil(java.lang.String delimiter, java.nio.charset.Charset charset)
          reads until the requested string is found.
 void readUntil(java.lang.String delimiter, java.nio.charset.Charset charset, StringReadCallback callback)
           
 void write(byte[] bytes)
           
 void write(java.nio.ByteBuffer buf)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketChannelWrapper

public SocketChannelWrapper(java.nio.channels.SocketChannel channel)
Method Detail

readUntil

public void readUntil(java.lang.String delimiter,
                      java.nio.charset.Charset charset,
                      StringReadCallback callback)

readUntil

public java.lang.String readUntil(java.lang.String delimiter,
                                  java.nio.charset.Charset charset)
                           throws TrendrrException
reads until the requested string is found.

Parameters:
delimiter -
charset -
Returns:
Throws:
TrendrrException

readBytes

public void readBytes(int numBytes,
                      ByteReadCallback callback)

readBytes

public byte[] readBytes(int numBytes)
                 throws TrendrrException
Throws:
TrendrrException

write

public void write(java.nio.ByteBuffer buf)

write

public void write(byte[] bytes)

hasWrites

public boolean hasWrites()
returns true if there are any writes waiting.

Returns:

hasReads

public boolean hasReads()
returns true if any reads are waiting.

Returns:

getChannel

public java.nio.channels.SocketChannel getChannel()

getWrites

public java.util.Queue<java.nio.ByteBuffer> getWrites()

doRead

public void doRead()
            throws TrendrrNoCallbackException,
                   TrendrrDisconnectedException,
                   TrendrrException
Attempts to read from the network, and process any callbacks. does nothing if no callbacks have been registered.

Throws:
TrendrrNoCallbackException
TrendrrDisconnectedException
TrendrrException

close

public void close()
attempts to process the remaining callbacks, then closes the channel and cleans up any resources.


isClosed

public boolean isClosed()