Class DirectByteBufferOutputStream

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

    public final class DirectByteBufferOutputStream
    extends java.io.OutputStream
    This class is a customized output stream implementation backed by ByteBuffer, which utilizes off heap memory when writing the data via MemoryPoolAssigner. Deletion of dataList, which is the memory this outputstream holds, occurs when the corresponding block is deleted.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closing this output stream has no effect.
      java.util.List<MemoryChunk> getMemoryChunkList()
      Returns the list of MemoryChunks that contains the written data.
      int size()
      Returns the size of the data written in this output stream.
      void write​(byte[] b)
      Writes b.length bytes from the specified byte array to this output stream.
      void write​(byte[] b, int off, int len)
      Writes len bytes from the specified byte array starting at offset off to this output stream.
      void write​(int b)
      Writes the specified byte to this output stream.
      • Methods inherited from class java.io.OutputStream

        flush, nullOutputStream
      • Methods inherited from class java.lang.Object

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

      • write

        public void write​(int b)
                   throws java.io.IOException
        Writes the specified byte to this output stream.
        Specified by:
        write in class java.io.OutputStream
        Parameters:
        b - the byte to be written.
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] b)
                   throws java.io.IOException
        Writes b.length bytes from the specified byte array to this output stream.
        Overrides:
        write in class java.io.OutputStream
        Parameters:
        b - the byte to be written.
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Writes len bytes from the specified byte array starting at offset off to this output stream.
        Overrides:
        write in class java.io.OutputStream
        Parameters:
        b - the data.
        off - the start offset in the data.
        len - the number of bytes to write.
        Throws:
        java.io.IOException
      • getMemoryChunkList

        public java.util.List<MemoryChunk> getMemoryChunkList()
        Returns the list of MemoryChunks that contains the written data. List of flipped and duplicated MemoryChunks are returned, which has independent position and limit, to reduce erroneous data read/write. This function has to be called when intended to read from the start of the list of MemoryChunks, not for additional write.
        Returns:
        the LinkedList of MemoryChunks.
      • size

        public int size()
        Returns the size of the data written in this output stream.
        Returns:
        the size of the data
      • close

        public void close()
        Closing this output stream has no effect.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream