Class InputOutputByteStream


  • @NotThreadSafe
    public class InputOutputByteStream
    extends java.lang.Object
    A byte buffer which supports both InputStream and OutputStream interfaces without needless copying of (potentially large) byte arrays. Not intended for multi-threaded access (no synchronization).
    • Constructor Detail

      • InputOutputByteStream

        public InputOutputByteStream​(byte[] adoptBuffer,
                                     int offset)
        Adopt a buffer which may already contain data
        Parameters:
        adoptBuffer -
        offset -
      • InputOutputByteStream

        public InputOutputByteStream​(java.nio.ByteBuffer bb)
        Initialize the internal buffer by copying the contents of the given ByteBuffer (which can be read-only).
        Parameters:
        bb -
    • Method Detail

      • size

        public int size()
        How many bytes have been written to the byte buffer
        Returns:
      • outputStream

        public java.io.OutputStream outputStream()
        Return a new output stream backed by the byte buffer managed by this.
        Returns:
        Throws:
        java.lang.IllegalStateException - if called after the mode has been flipped to read.
      • inputStream

        public java.io.InputStream inputStream()
        Provide a new InputStream with its own dedicated position starting at 0 offset
        Returns:
      • wrap

        public java.nio.ByteBuffer wrap()
        Provides a wrapped version of the internal buffer.
        Returns:
        a read-only ByteBuffer.
      • reset

        public void reset()
        Reset the offset to make the buffer appear empty. Does not change the current length (capacity). Note that any streams currently being used to read the data will end.
      • getRawBuffer

        public byte[] getRawBuffer()
        Get the underlying byte[] buffer at the current point in time.
        Returns: