Class 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 a ByteBuffer.
    Author:
    Jerome Louvel
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 of IoUtils.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 the Level.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 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:
        java.io.IOException