org.restlet.util
Class ReadingListener

java.lang.Object
  extended by org.restlet.util.ReadingListener
All Implemented Interfaces:
SelectionListener
Direct Known Subclasses:
ByteReadingListener

public abstract class ReadingListener
extends Object
implements SelectionListener

Selection listener notifying new content is read into a ByteBuffer.

Author:
Jerome Louvel

Constructor Summary
ReadingListener(ReadableByteChannel byteChannel, ByteBuffer byteBuffer)
          Constructor.
ReadingListener(ReadableByteChannel byteChannel, int bufferSize)
          Constructor.
ReadingListener(Representation source)
          Default constructor.
ReadingListener(Representation source, int bufferSize)
          Constructor.
 
Method Summary
protected abstract  void onContent(ByteBuffer byteBuffer)
          Callback invoked when new content is available.
protected  void onEnd()
          Callback invoked when the end of the representation has been reached.
protected  void onError(IOException ioe)
          Callback invoked when an IO exception occurs.
 void onSelected(SelectionRegistration selectionRegistration)
          Callback invoked when new content is available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadingListener

public ReadingListener(ReadableByteChannel byteChannel,
                       ByteBuffer byteBuffer)
                throws IOException
Constructor. Uses a byte buffer of a given size.

Parameters:
byteChannel - The source byte channel.
byteBuffer - The byte buffer to use.
Throws:
IOException

ReadingListener

public ReadingListener(ReadableByteChannel byteChannel,
                       int bufferSize)
                throws IOException
Constructor. Uses a byte buffer of a given size.

Parameters:
byteChannel - The source byte channel.
bufferSize - The size of the byte buffer to use.
Throws:
IOException

ReadingListener

public ReadingListener(Representation source)
                throws IOException
Default constructor. Uses a byte buffer of IoUtils.BUFFER_SIZE length.

Parameters:
source - The source representation.
Throws:
IOException

ReadingListener

public ReadingListener(Representation source,
                       int bufferSize)
                throws IOException
Constructor. Uses a byte buffer of a given size.

Parameters:
source - The source byte channel.
bufferSize - The size of the byte buffer to use.
Throws:
IOException
Method Detail

onContent

protected abstract void onContent(ByteBuffer byteBuffer)
Callback invoked when new content is available.

Parameters:
byteBuffer - The byte buffer filled with the new content (correctly flip).

onEnd

protected void onEnd()
Callback invoked when the end of the representation has been reached. By default, it does nothing.


onError

protected void onError(IOException ioe)
Callback invoked when an IO exception occurs. By default, it logs the exception at the Level.WARNING level.

Parameters:
ioe - The exception caught.

onSelected

public final void onSelected(SelectionRegistration selectionRegistration)
                      throws IOException
Callback invoked when new content is available. It reads the available bytes from the source channel into an internal buffer then calls onContent(ByteBuffer) method or the onEnd() method or the onError(IOException) method.

Specified by:
onSelected in interface SelectionListener
Parameters:
selectionRegistration - The selected registration.
Throws:
IOException


Copyright © 2005-2013 Restlet.