Package org.agrona.io

Class DirectBufferOutputStream

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

    public class DirectBufferOutputStream
    extends java.io.OutputStream
    OutputStream that wraps an underlying MutableDirectBuffer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      MutableDirectBuffer buffer()
      The underlying buffer being wrapped.
      void close()
      Override to remove IOException.
      void flush()
      Override to remove IOException.
      int length()
      The length of the underlying buffer to use.
      int offset()
      The offset within the underlying buffer at which to start.
      int position()
      The position in the buffer from the offset up to which has been written.
      void wrap​(MutableDirectBuffer buffer)
      Wrap the buffer.
      void wrap​(MutableDirectBuffer buffer, int offset, int length)
      Wrap the buffer at an offset.
      void write​(byte[] srcBytes)
      Write a byte[] to the buffer.
      void write​(byte[] srcBytes, int srcOffset, int length)
      Write a byte[] to the buffer.
      void write​(int b)
      Write a byte to buffer.
      • 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
    • Field Detail

      • offset

        private int offset
      • length

        private int length
      • position

        private int position
    • Constructor Detail

      • 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 Detail

      • 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 java.io.OutputStream
        Parameters:
        b - to be written.
        Throws:
        java.lang.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 java.io.OutputStream
        Parameters:
        srcBytes - to write
        srcOffset - at which to begin reading bytes from the srcBytes.
        length - of the srcBytes to read.
        Throws:
        java.lang.IllegalStateException - if insufficient capacity remains in the buffer.
      • write

        public void write​(byte[] srcBytes)
        Write a byte[] to the buffer.
        Overrides:
        write in class java.io.OutputStream
        Parameters:
        srcBytes - to write
        Throws:
        java.lang.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 java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
      • close

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