Class ByteBufferOutputStream

  • All Implemented Interfaces:
    DirectDataOutput, RandomAccessOutputStream, java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    @NotThreadSafe
    public class ByteBufferOutputStream
    extends java.io.OutputStream
    implements RandomAccessOutputStream
    An OutputStream that is backed by a ByteBuffer which can be resized as needed. Prefer using this instead of ByteArrayOutputStream since this makes direct use of ByteBuffer intrinsic methods for writing primitive types (see DirectDataOutput for example).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void flush()  
      ByteArraySegment getData()
      Returns a ByteArraySegment wrapping the current contents of the RandomAccessOutputStream.
      int size()
      Gets a value indicating the size of this OutputStream.
      void write​(byte[] array)  
      void write​(byte[] b, int offset, int length)  
      void write​(byte[] array, int arrayOffset, int length, int streamPosition)
      Writes a sequence of bytes at the given position.
      void write​(int b)  
      void write​(int byteValue, int streamPosition)
      Writes the given byte value at the given position.
      void writeBuffer​(BufferView buffer)
      Includes the given BufferView.
      void writeInt​(int intValue)
      Writes the given value as a 32 bit Integer.
      void writeInt​(int intValue, int streamPosition)
      Writes the given Int value at the given position.
      void writeLong​(long longValue)
      Writes the given value as a 64 bit Long.
      void writeShort​(int shortValue)
      Writes the given value as a 16 bit Short.
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

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

      • ByteBufferOutputStream

        public ByteBufferOutputStream()
        Creates a new instance of the ByteBufferOutputStream.
      • ByteBufferOutputStream

        public ByteBufferOutputStream​(int initialSize)
        Creates a new instance of the ByteBufferOutputStream with given initial size.
        Parameters:
        initialSize - The initial size to create with.
    • Method Detail

      • write

        public void write​(int b)
        Specified by:
        write in class java.io.OutputStream
      • write

        public void write​(int byteValue,
                          int streamPosition)
        Description copied from interface: RandomAccessOutputStream
        Writes the given byte value at the given position.
        Specified by:
        write in interface RandomAccessOutputStream
        Parameters:
        byteValue - The value to write.
        streamPosition - The position to write at.
      • write

        public void write​(byte[] array)
        Overrides:
        write in class java.io.OutputStream
      • write

        public void write​(byte[] b,
                          int offset,
                          int length)
        Overrides:
        write in class java.io.OutputStream
      • write

        public void write​(byte[] array,
                          int arrayOffset,
                          int length,
                          int streamPosition)
        Description copied from interface: RandomAccessOutputStream
        Writes a sequence of bytes at the given position. NOTE: depending on the implementation of this interface, this may result in increasing the size of the stream. For example, if position is smaller than size() AND position + length is larger than size() then the extra bytes may be appended at the end, if the underlying OutputStream's structure permits it.
        Specified by:
        write in interface RandomAccessOutputStream
        Parameters:
        array - The buffer to write from.
        arrayOffset - The offset within the buffer to start at.
        length - The number of bytes to write.
        streamPosition - The position within the OutputStream to write at.
      • flush

        public void flush()
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
      • writeShort

        public void writeShort​(int shortValue)
        Description copied from interface: DirectDataOutput
        Writes the given value as a 16 bit Short. Every effort will be made to write this using efficient techniques (such as making use of intrinsic instructions).
        Specified by:
        writeShort in interface DirectDataOutput
        Parameters:
        shortValue - The Short value to write.
      • writeInt

        public void writeInt​(int intValue)
        Description copied from interface: DirectDataOutput
        Writes the given value as a 32 bit Integer. Every effort will be made to write this using efficient techniques (such as making use of intrinsic instructions).
        Specified by:
        writeInt in interface DirectDataOutput
        Parameters:
        intValue - The Integer value to write.
      • writeInt

        public void writeInt​(int intValue,
                             int streamPosition)
        Description copied from interface: RandomAccessOutputStream
        Writes the given Int value at the given position.
        Specified by:
        writeInt in interface RandomAccessOutputStream
        Parameters:
        intValue - The value to write.
        streamPosition - The position to write at.
      • writeLong

        public void writeLong​(long longValue)
        Description copied from interface: DirectDataOutput
        Writes the given value as a 64 bit Long. Every effort will be made to write this using efficient techniques (such as making use of intrinsic instructions).
        Specified by:
        writeLong in interface DirectDataOutput
        Parameters:
        longValue - The Long value to write.