Package org.agrona.io

Class DirectBufferOutputStream

java.lang.Object
java.io.OutputStream
org.agrona.io.DirectBufferOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class DirectBufferOutputStream extends OutputStream
OutputStream that wraps an underlying MutableDirectBuffer.
  • Field Details

    • buffer

      private MutableDirectBuffer buffer
    • offset

      private int offset
    • length

      private int length
    • position

      private int position
  • Constructor Details

    • DirectBufferOutputStream

      public DirectBufferOutputStream()
      Default constructor.
    • DirectBufferOutputStream

      public DirectBufferOutputStream(MutableDirectBuffer buffer)
      Constructs output stream wrapping the given buffer.
      Parameters:
      buffer - to wrap.
    • DirectBufferOutputStream

      public DirectBufferOutputStream(MutableDirectBuffer buffer, int offset, int length)
      Constructs output stream wrapping the given buffer at an offset.
      Parameters:
      buffer - to wrap.
      offset - in the buffer.
      length - size in bytes to wrap.
  • Method Details

    • wrap

      public void wrap(MutableDirectBuffer buffer)
      Wrap the buffer.
      Parameters:
      buffer - to wrap.
    • wrap

      public void wrap(MutableDirectBuffer buffer, int offset, int length)
      Wrap the buffer at an offset.
      Parameters:
      buffer - to wrap.
      offset - in the buffer.
      length - size in bytes to wrap.
    • position

      public int position()
      The position in the buffer from the offset up to which has been written.
      Returns:
      the position in the buffer from the offset up to which has been written.
    • offset

      public int offset()
      The offset within the underlying buffer at which to start.
      Returns:
      offset within the underlying buffer at which to start.
    • buffer

      public MutableDirectBuffer buffer()
      The underlying buffer being wrapped.
      Returns:
      the underlying buffer being wrapped.
    • length

      public int length()
      The length of the underlying buffer to use
      Returns:
      length of the underlying buffer to use
    • write

      public void write(int b)
      Write a byte to buffer.
      Specified by:
      write in class OutputStream
      Parameters:
      b - to be written.
      Throws:
      IllegalStateException - if insufficient capacity remains in the buffer.
    • write

      public void write(byte[] srcBytes, int srcOffset, int length)
      Write a byte[] to the buffer.
      Overrides:
      write in class OutputStream
      Parameters:
      srcBytes - to write
      srcOffset - at which to begin reading bytes from the srcBytes.
      length - of the srcBytes to read.
      Throws:
      IllegalStateException - if insufficient capacity remains in the buffer.
    • write

      public void write(byte[] srcBytes)
      Write a byte[] to the buffer.
      Overrides:
      write in class OutputStream
      Parameters:
      srcBytes - to write
      Throws:
      IllegalStateException - if insufficient capacity remains in the buffer.
    • flush

      public void flush()
      Override to remove IOException. This method does nothing.
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
    • close

      public void close()
      Override to remove IOException. This method does nothing.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream