Package org.restlet.util
Class ReadingListener
- java.lang.Object
-
- org.restlet.util.ReadingListener
-
- All Implemented Interfaces:
SelectionListener
- Direct Known Subclasses:
ByteReadingListener
public abstract class ReadingListener extends java.lang.Object implements SelectionListener
Selection listener notifying new content is read into aByteBuffer
.- Author:
- Jerome Louvel
-
-
Constructor Summary
Constructors Constructor Description ReadingListener(java.nio.channels.ReadableByteChannel byteChannel, int bufferSize)
Constructor.ReadingListener(java.nio.channels.ReadableByteChannel byteChannel, java.nio.ByteBuffer byteBuffer)
Constructor.ReadingListener(Representation source)
Default constructor.ReadingListener(Representation source, int bufferSize)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
onContent(java.nio.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(java.io.IOException ioe)
Callback invoked when an IO exception occurs.void
onSelected(SelectionRegistration selectionRegistration)
Callback invoked when new content is available.
-
-
-
Constructor Detail
-
ReadingListener
public ReadingListener(java.nio.channels.ReadableByteChannel byteChannel, java.nio.ByteBuffer byteBuffer) throws java.io.IOException
Constructor. Uses a byte buffer of a given size.- Parameters:
byteChannel
- The source byte channel.byteBuffer
- The byte buffer to use.- Throws:
java.io.IOException
-
ReadingListener
public ReadingListener(java.nio.channels.ReadableByteChannel byteChannel, int bufferSize) throws java.io.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:
java.io.IOException
-
ReadingListener
public ReadingListener(Representation source) throws java.io.IOException
Default constructor. Uses a byte buffer ofIoUtils.BUFFER_SIZE
length.- Parameters:
source
- The source representation.- Throws:
java.io.IOException
-
ReadingListener
public ReadingListener(Representation source, int bufferSize) throws java.io.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:
java.io.IOException
-
-
Method Detail
-
onContent
protected abstract void onContent(java.nio.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(java.io.IOException ioe)
Callback invoked when an IO exception occurs. By default, it logs the exception at theLevel.WARNING
level.- Parameters:
ioe
- The exception caught.
-
onSelected
public final void onSelected(SelectionRegistration selectionRegistration) throws java.io.IOException
Callback invoked when new content is available. It reads the available bytes from the source channel into an internal buffer then callsonContent(ByteBuffer)
method or theonEnd()
method or theonError(IOException)
method.- Specified by:
onSelected
in interfaceSelectionListener
- Parameters:
selectionRegistration
- The selected registration.- Throws:
java.io.IOException
-
-