Class ByteBufferInputStream

java.lang.Object
java.io.InputStream
com.helger.base.io.stream.ByteBufferInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

@NotThreadSafe public final class ByteBufferInputStream extends InputStream
InputStream wrapped around a single ByteBuffer.
Author:
Philip Helger
  • Constructor Details

    • ByteBufferInputStream

      public ByteBufferInputStream(@NonNull ByteBuffer aBuffer)
      Constructor
      Parameters:
      aBuffer - ByteBuffer to use. May not be null.
  • Method Details

    • isClosed

      public boolean isClosed()
      Returns:
      true if this stream has been closed, false otherwise.
    • getBuffer

      public @Nullable ByteBuffer getBuffer()
      Returns:
      The contained ByteBuffer. Handle with care! May be null if the stream is closed!
    • isAnythingAvailable

      public boolean isAnythingAvailable()
      Returns:
      true if there is at least one byte remaining to be read, false otherwise.
    • available

      @Nonnegative public int available()
      Overrides:
      available in class InputStream
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
    • mark

      public void mark(int nReadlimit)
      Overrides:
      mark in class InputStream
    • reset

      public void reset()
      Overrides:
      reset in class InputStream
    • markSupported

      public boolean markSupported()
      Overrides:
      markSupported in class InputStream
    • read

      public int read()
      Specified by:
      read in class InputStream
    • read

      public int read(byte @NonNull [] aBuf)
      Overrides:
      read in class InputStream
    • read

      public int read(byte @NonNull [] aBuffer, @Nonnegative int nOfs, @Nonnegative int nLen)
      Overrides:
      read in class InputStream
    • skip

      @Nonnegative public long skip(long nBytesToSkip)
      Overrides:
      skip in class InputStream
    • read

      @Nonnegative public long read(@NonNull ByteBuffer aDestByteBuffer)
      Reads as much as possible into the destination buffer.
      Parameters:
      aDestByteBuffer - The destination byte buffer to use. May not be null.
      Returns:
      The number of bytes read. Always ≥ 0.