Class BytesStreamOutput

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable
    Direct Known Subclasses:
    ReleasableBytesStreamOutput

    public class BytesStreamOutput
    extends BytesStream
    A @link StreamOutput that uses BigArrays to acquire pages of bytes, which avoids frequent reallocation & copying of the internal data.
    • Field Detail

      • bigArrays

        protected final BigArrays bigArrays
      • count

        protected int count
    • Constructor Detail

      • BytesStreamOutput

        public BytesStreamOutput()
        Create a non recycling BytesStreamOutput with an initial capacity of 0.
      • BytesStreamOutput

        public BytesStreamOutput​(int expectedSize)
        Create a non recycling BytesStreamOutput with enough initial pages acquired to satisfy the capacity given by expected size.
        Parameters:
        expectedSize - the expected maximum size of the stream in bytes.
      • BytesStreamOutput

        protected BytesStreamOutput​(int expectedSize,
                                    BigArrays bigArrays)
    • Method Detail

      • position

        public long position()
                      throws java.io.IOException
        Overrides:
        position in class StreamOutput
        Throws:
        java.io.IOException
      • writeByte

        public void writeByte​(byte b)
                       throws java.io.IOException
        Description copied from class: StreamOutput
        Writes a single byte.
        Specified by:
        writeByte in class StreamOutput
        Throws:
        java.io.IOException
      • writeBytes

        public void writeBytes​(byte[] b,
                               int offset,
                               int length)
        Description copied from class: StreamOutput
        Writes an array of bytes.
        Specified by:
        writeBytes in class StreamOutput
        Parameters:
        b - the bytes to write
        offset - the offset in the byte array
        length - the number of bytes to write
      • flush

        public void flush()
                   throws java.io.IOException
        Description copied from class: StreamOutput
        Forces any buffered output to be written.
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in class StreamOutput
        Throws:
        java.io.IOException
      • seek

        public void seek​(long position)
        Overrides:
        seek in class StreamOutput
      • skip

        public void skip​(int length)
      • close

        public void close()
        Description copied from class: StreamOutput
        Closes this stream to further operations.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class StreamOutput
      • size

        public int size()
        Returns the current size of the buffer.
        Returns:
        the value of the count field, which is the number of valid bytes in this output stream.
        See Also:
        ByteArrayOutputStream.count
      • ramBytesUsed

        public long ramBytesUsed()
        Returns the number of bytes used by the underlying ByteArray
        See Also:
        Accountable.ramBytesUsed()