Class CallbackReadableByteChannel

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

    public class CallbackReadableByteChannel
    extends java.lang.Object
    implements java.nio.channels.ReadableByteChannel
    A ReadableByteChannel with an optional callback lambda to show the progress.
    • Constructor Summary

      Constructors 
      Constructor Description
      CallbackReadableByteChannel​(java.nio.channels.ReadableByteChannel channel, long expectedSize, java.util.function.Consumer<java.lang.Double> progressConsumer)
      Creates a callback read channel.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      int getSize()
      Gets the number of bytes read so far.
      boolean isOpen()  
      int read​(java.nio.ByteBuffer dst)  
      • Methods inherited from class java.lang.Object

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

      • CallbackReadableByteChannel

        public CallbackReadableByteChannel​(java.nio.channels.ReadableByteChannel channel,
                                           long expectedSize,
                                           java.util.function.Consumer<java.lang.Double> progressConsumer)
        Creates a callback read channel.
        Parameters:
        channel - the channel to be wrapped
        expectedSize - the expected size, negative if indefinite
        progressConsumer - the optional consumer receiving the progress from 0.0 to 1.0 (negative if indefinite), null if none
    • Method Detail

      • 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
      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
      • 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
      • getSize

        public int getSize()
        Gets the number of bytes read so far.
        Returns:
        the size