Class NbChannelInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class NbChannelInputStream
    extends java.io.InputStream
    Input stream connected to a non-blocking readable channel.
    • Constructor Summary

      Constructors 
      Constructor Description
      NbChannelInputStream​(java.nio.channels.ReadableByteChannel channel)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int read()  
      int read​(byte[] b, int off, int len)  
      private int readChannel()
      Reads the available bytes from the channel into the byte buffer.
      private void refill()
      Refill the byte buffer by attempting to read the channel.
      • Methods inherited from class java.io.InputStream

        available, close, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

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

      • byteBuffer

        private final java.nio.ByteBuffer byteBuffer
        The internal byte buffer.
      • channel

        private final java.nio.channels.ReadableByteChannel channel
        The channel to read from.
      • endReached

        private volatile boolean endReached
        Indicates if further reads can be attempted.
      • selectionRegistration

        private volatile SelectionRegistration selectionRegistration
        The registered selection registration.
      • selectableChannel

        private final java.nio.channels.SelectableChannel selectableChannel
        The optional selectable channel to read from.
      • selectionChannel

        private final SelectionChannel selectionChannel
        The optional selection channel to read from.
    • Constructor Detail

      • NbChannelInputStream

        public NbChannelInputStream​(java.nio.channels.ReadableByteChannel channel)
        Constructor.
        Parameters:
        channel - The channel to read from.
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • readChannel

        private int readChannel()
                         throws java.io.IOException
        Reads the available bytes from the channel into the byte buffer.
        Returns:
        The number of bytes read or -1 if the end of channel has been reached.
        Throws:
        java.io.IOException
      • refill

        private void refill()
                     throws java.io.IOException
        Refill the byte buffer by attempting to read the channel.
        Throws:
        java.io.IOException