Class ByteBufferInput

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

    public class ByteBufferInput
    extends java.io.InputStream
    implements ByteInput
    An InputStream which implements ByteInput and reads bytes from a ByteBuffer.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.ByteBuffer buffer  
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteBufferInput​(java.nio.ByteBuffer buffer)
      Construct a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()
      Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.
      void close()
      int read()
      Reads the next byte of data from the input stream.
      int read​(byte[] b)
      Read some bytes from the input stream into the given array.
      int read​(byte[] b, int off, int len)
      Read some bytes from the input stream into the given array.
      long skip​(long n)
      Skips over and discards up to n bytes of data from this input stream.
      • Methods inherited from class java.io.InputStream

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

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

      • buffer

        private final java.nio.ByteBuffer buffer
    • Constructor Detail

      • ByteBufferInput

        public ByteBufferInput​(java.nio.ByteBuffer buffer)
        Construct a new instance.
        Parameters:
        buffer - the buffer to read from
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Reads the next byte of data from the input stream. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
        Specified by:
        read in interface ByteInput
        Specified by:
        read in class java.io.InputStream
        Returns:
        the next byte, or -1 if the end of stream has been reached
        Throws:
        java.io.IOException - if an error occurs
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Read some bytes from the input stream into the given array. Returns the number of bytes actually read (possibly zero), or -1 if the end of stream has been reached.
        Specified by:
        read in interface ByteInput
        Overrides:
        read in class java.io.InputStream
        Parameters:
        b - the destination array
        Returns:
        the number of bytes read (possibly zero), or -1 if the end of stream has been reached
        Throws:
        java.io.IOException - if an error occurs
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Read some bytes from the input stream into the given array. Returns the number of bytes actually read (possibly zero), or -1 if the end of stream has been reached.
        Specified by:
        read in interface ByteInput
        Overrides:
        read in class java.io.InputStream
        Parameters:
        b - the destination array
        off - the offset into the array into which data should be read
        len - the number of bytes to attempt to fill in the destination array
        Returns:
        the number of bytes read (possibly zero), or -1 if the end of stream has been reached
        Throws:
        java.io.IOException - if an error occurs
      • available

        public int available()
                      throws java.io.IOException
        Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.
        Specified by:
        available in interface ByteInput
        Overrides:
        available in class java.io.InputStream
        Returns:
        the number of bytes
        Throws:
        java.io.IOException - if an error occurs
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Skips over and discards up to n bytes of data from this input stream. If the end of stream is reached, this method returns 0 in order to be consistent with InputStream.skip(long).
        Specified by:
        skip in interface ByteInput
        Overrides:
        skip in class java.io.InputStream
        Parameters:
        n - the number of bytes to attempt to skip
        Returns:
        the number of bytes skipped
        Throws:
        java.io.IOException - if an error occurs
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException