org.restlet.util
Class ReadableListener

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

public abstract class ReadableListener
extends Object
implements SelectionListener

Selection listener notifying new content as an ByteBuffer.

Author:
Jerome Louvel

Constructor Summary
ReadableListener(Representation source)
          Default constructor.
ReadableListener(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()
          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

ReadableListener

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

Parameters:
source - The source representation.
Throws:
IOException

ReadableListener

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

Parameters:
source - The source byte channel.
bufferSize - 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()
Callback invoked when new content is available. It reads the available bytes from the source channel into an internal buffer then calls onContent(ByteBuffer).

Specified by:
onSelected in interface SelectionListener


Copyright © 2005-2012 Restlet S.A.S..