com.trendrr.oss.networking
Class AsynchBuffer

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

public class AsynchBuffer
extends java.lang.Object

Author:
Dustin Norlander

Constructor Summary
AsynchBuffer()
           
 
Method Summary
 void close()
          closes the buffer.
 int getBytesPerRead()
           
 boolean hasCallbacksWaiting()
           
 void process()
          attempts to read the requested data from the buffers.
 int read(java.nio.channels.ReadableByteChannel channel)
          reads one buffer (or less) worth of bytes from the channel.
 byte[] readBytes(int numBytes)
           
 void readBytes(int numBytes, ByteReadCallback callback)
          reads the specified number of bytes from the channel, calls the callback when requested bytes are available.
 java.lang.String readUntil(java.lang.String delimiter, java.nio.charset.Charset charset)
          reads until the requested delimiter.
 void readUntil(java.lang.String delimiter, java.nio.charset.Charset charset, StringReadCallback callback)
          Reads from the socketchannel until the delimiter is encountered.
 void setBytesPerRead(int bytesPerRead)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsynchBuffer

public AsynchBuffer()
Method Detail

readUntil

public void readUntil(java.lang.String delimiter,
                      java.nio.charset.Charset charset,
                      StringReadCallback callback)
Reads from the socketchannel until the delimiter is encountered. this method returns immediately, the callback is invoked once the data is available.

Parameters:
delimiter -
callback -
charset -

readUntil

public java.lang.String readUntil(java.lang.String delimiter,
                                  java.nio.charset.Charset charset)
                           throws TrendrrException
reads until the requested delimiter. this method blocks until data is available.

Parameters:
dilimiter -
charset -
Throws:
TrendrrException

readBytes

public void readBytes(int numBytes,
                      ByteReadCallback callback)
reads the specified number of bytes from the channel, calls the callback when requested bytes are available.

Parameters:
numBytes -
callback -

readBytes

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

read

public int read(java.nio.channels.ReadableByteChannel channel)
         throws TrendrrDisconnectedException,
                TrendrrException
reads one buffer (or less) worth of bytes from the channel. channel settings. after calling read it is up to the caller to call process, in order to process the bytes.

Parameters:
channel -
Returns:
Throws:
TrendrrException
TrendrrDisconnectedException

getBytesPerRead

public int getBytesPerRead()

setBytesPerRead

public void setBytesPerRead(int bytesPerRead)

process

public void process()
attempts to read the requested data from the buffers. appropriate callback will be called if requested data is available. Exceptions are sent to the callbacks.


close

public void close()
closes the buffer. clears and discards all buffers. Sends a TrendrrDisconnectedException to all waiting callbacks.


hasCallbacksWaiting

public boolean hasCallbacksWaiting()