Class InputStreamChannel

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

    public class InputStreamChannel
    extends java.lang.Object
    implements java.nio.channels.ReadableByteChannel, BlockableChannel
    Readable byte channel wrapping an input stream.
    Author:
    Jerome Louvel
    • Constructor Summary

      Constructors 
      Constructor Description
      InputStreamChannel​(java.io.InputStream inputStream)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the underlying input stream.
      protected java.io.InputStream getInputStream()
      Returns the underlying input stream.
      boolean isBlocking()
      True if the underlying input stream is able to indicate available bytes upfront.
      boolean isOpen()
      Indicates if the channel and its underlying stream are open.
      int read​(java.nio.ByteBuffer target)
      Reads bytes from the underlying stream to the target buffer.
      • Methods inherited from class java.lang.Object

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

      • InputStreamChannel

        public InputStreamChannel​(java.io.InputStream inputStream)
                           throws java.io.IOException
        Constructor.
        Parameters:
        inputStream -
        Throws:
        java.io.IOException
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Closes the underlying input stream.
        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
      • getInputStream

        protected java.io.InputStream getInputStream()
        Returns the underlying input stream.
        Returns:
        The underlying input stream.
      • isBlocking

        public boolean isBlocking()
        True if the underlying input stream is able to indicate available bytes upfront.
        Specified by:
        isBlocking in interface BlockableChannel
        Returns:
        True if the channel is blocking.
      • isOpen

        public boolean isOpen()
        Indicates if the channel and its underlying stream are open.
        Specified by:
        isOpen in interface java.nio.channels.Channel
        Returns:
        True if the channel and its underlying stream are open.
      • read

        public int read​(java.nio.ByteBuffer target)
                 throws java.io.IOException
        Reads bytes from the underlying stream to the target buffer.
        Specified by:
        read in interface java.nio.channels.ReadableByteChannel
        Parameters:
        target - The target byte buffer.
        Returns:
        The number of bytes read.
        Throws:
        java.io.IOException