Class ByteBuffersDataOutput

    • Field Detail

      • NO_REUSE

        public static final Consumer<ByteBuffer> NO_REUSE
        A singleton instance of "no-reuse" buffer strategy.
      • DEFAULT_MIN_BITS_PER_BLOCK

        public static final int DEFAULT_MIN_BITS_PER_BLOCK
        Default minBitsPerBlock
        See Also:
        Constant Field Values
      • DEFAULT_MAX_BITS_PER_BLOCK

        public static final int DEFAULT_MAX_BITS_PER_BLOCK
        Default maxBitsPerBlock
        See Also:
        Constant Field Values
      • LIMIT_MIN_BITS_PER_BLOCK

        public static final int LIMIT_MIN_BITS_PER_BLOCK
        Smallest minBitsPerBlock allowed
        See Also:
        Constant Field Values
      • LIMIT_MAX_BITS_PER_BLOCK

        public static final int LIMIT_MAX_BITS_PER_BLOCK
        Largest maxBitsPerBlock allowed
        See Also:
        Constant Field Values
    • Constructor Detail

      • ByteBuffersDataOutput

        public ByteBuffersDataOutput​(long expectedSize)
        Create a new output, suitable for writing a file of around expectedSize bytes.

        Memory allocation will be optimized based on the expectedSize hint, so that there is less overhead for larger files.

        Parameters:
        expectedSize - estimated size of the output file
      • ByteBuffersDataOutput

        public ByteBuffersDataOutput()
        Creates a new output with all defaults.
      • ByteBuffersDataOutput

        public ByteBuffersDataOutput​(int minBitsPerBlock,
                                     int maxBitsPerBlock,
                                     IntFunction<ByteBuffer> blockAllocate,
                                     Consumer<ByteBuffer> blockReuse)
        Expert: Creates a new output with custom parameters.
        Parameters:
        minBitsPerBlock - minimum bits per block
        maxBitsPerBlock - maximum bits per block
        blockAllocate - block allocator
        blockReuse - block recycler
    • Method Detail

      • writeByte

        public void writeByte​(byte b)
        Description copied from class: DataOutput
        Writes a single byte.

        The most primitive data type is an eight-bit byte. Files are accessed as sequences of bytes. All other data types are defined as sequences of bytes, so file formats are byte-order independent.

        Specified by:
        writeByte in class DataOutput
        See Also:
        DataInput.readByte()
      • writeBytes

        public void writeBytes​(byte[] src,
                               int offset,
                               int length)
        Description copied from class: DataOutput
        Writes an array of bytes.
        Specified by:
        writeBytes in class DataOutput
        Parameters:
        src - the bytes to write
        offset - the offset in the byte array
        length - the number of bytes to write
        See Also:
        DataInput.readBytes(byte[],int,int)
      • writeBytes

        public void writeBytes​(byte[] b)
      • writeBytes

        public void writeBytes​(ByteBuffer buffer)
      • toBufferList

        public ArrayList<ByteBuffer> toBufferList()
        Return a list of read-only view of ByteBuffer blocks over the current content written to the output.
      • toWriteableBufferList

        public ArrayList<ByteBuffer> toWriteableBufferList()
        Returns a list of writeable blocks over the (source) content buffers.

        This method returns the raw content of source buffers that may change over the lifetime of this object (blocks can be recycled or discarded, for example). Most applications should favor calling toBufferList() which returns a read-only view over the content of the source buffers.

        The difference between toBufferList() and toWriteableBufferList() is that read-only view of source buffers will always return false from ByteBuffer.hasArray() (which sometimes may be required to avoid double copying).

      • toArrayCopy

        public byte[] toArrayCopy()
        Return a contiguous array with the current content written to the output. The returned array is always a copy (can be mutated).

        If the size() of the underlying buffers exceeds maximum size of Java array, an RuntimeException will be thrown.

      • size

        public long size()
        Returns:
        The number of bytes written to this output so far.
      • writeMapOfStrings

        public void writeMapOfStrings​(Map<String,​String> map)
        Description copied from class: DataOutput
        Writes a String map.

        First the size is written as an vInt, followed by each key-value pair written as two consecutive Strings.

        Overrides:
        writeMapOfStrings in class DataOutput
        Parameters:
        map - Input map.
      • writeSetOfStrings

        public void writeSetOfStrings​(Set<String> set)
        Description copied from class: DataOutput
        Writes a String set.

        First the size is written as an vInt, followed by each value written as a String.

        Overrides:
        writeSetOfStrings in class DataOutput
        Parameters:
        set - Input set.
      • ramBytesUsed

        public long ramBytesUsed()
        Description copied from interface: Accountable
        Return the memory usage of this object in bytes. Negative values are illegal.
        Specified by:
        ramBytesUsed in interface Accountable
      • reset

        public void reset()
        This method resets this object to a clean (zero-size) state and publishes any currently allocated buffers for reuse to the reuse strategy provided in the constructor.

        Sharing byte buffers for reads and writes is dangerous and will very likely lead to hard-to-debug issues, use with great care.