Class RewindableReadableByteChannel

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel

    public final class RewindableReadableByteChannel
    extends java.lang.Object
    implements java.nio.channels.ReadableByteChannel
    A wrapper around ReadableByteChannel that provides rewinding feature: it caches the read bytes so that after reading some initial part of the channel, one can "rewind" the channel and again read the bytes from the beginning. Once the rewinding feature is not needed any more, it can be disabled via disableRewinding(): this frees the cache memory and forwadrds the subsequent read(java.nio.ByteBuffer)-calls directly to the wrapped channel.
    Since:
    1.1.0
    • Constructor Summary

      Constructors 
      Constructor Description
      RewindableReadableByteChannel​(java.nio.channels.ReadableByteChannel baseChannel)
      Constructs a wrapper around baseChannel.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void disableRewinding()
      Disables the rewinding feature.
      boolean isOpen()  
      int read​(java.nio.ByteBuffer dst)  
      void rewind()
      Rewinds this buffer to the beginning (if rewinding is still enabled).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RewindableReadableByteChannel

        public RewindableReadableByteChannel​(java.nio.channels.ReadableByteChannel baseChannel)
        Constructs a wrapper around baseChannel. After wrapping baseChannel should not be manipulated externally.
    • Method Detail

      • disableRewinding

        public void disableRewinding()
        Disables the rewinding feature. After calling this method the attempts to rewind this channel will fail, and the subsequent read()-calls will be forwarded directly to the wrapped channel (after the currently buffered bytes are read).
      • rewind

        public void rewind()
                    throws java.io.IOException
        Rewinds this buffer to the beginning (if rewinding is still enabled).
        Throws:
        java.io.IOException
      • read

        public int read​(java.nio.ByteBuffer dst)
                 throws java.io.IOException
        Specified by:
        read in interface java.nio.channels.ReadableByteChannel
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel