Class UnsafeByteBufferOutput

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

    public class UnsafeByteBufferOutput
    extends ByteBufferOutput
    A ByteBufferOutput that writes data to a direct ByteBuffer (off-heap memory) using sun.misc.Unsafe. Multi-byte primitive types use native byte order, so the native byte order on different computers which read and write the data must be the same.

    Not available on all JVMs. Util.unsafe can be checked before using this class.

    This class may be much faster when Output.setVariableLengthEncoding(boolean) is false.

    Author:
    Roman Levenstein , Nathan Sweet
    • Constructor Detail

      • UnsafeByteBufferOutput

        public UnsafeByteBufferOutput​(int bufferSize)
        Creates a new Output for writing to a direct ByteBuffer.
        Parameters:
        bufferSize - The size of the buffer. An exception is thrown if more bytes than this are written and ByteBufferOutput.flush() does not empty the buffer.
      • UnsafeByteBufferOutput

        public UnsafeByteBufferOutput​(int bufferSize,
                                      int maxBufferSize)
        Creates a new Output for writing to a direct ByteBuffer.
        Parameters:
        bufferSize - The initial size of the buffer.
        maxBufferSize - If ByteBufferOutput.flush() does not empty the buffer, the buffer is doubled as needed until it exceeds maxBufferSize and an exception is thrown. Can be -1 for no maximum.
      • UnsafeByteBufferOutput

        public UnsafeByteBufferOutput​(java.io.OutputStream outputStream)
        Creates a new Output for writing to an OutputStream. A buffer size of 4096 is used.
      • UnsafeByteBufferOutput

        public UnsafeByteBufferOutput​(java.io.OutputStream outputStream,
                                      int bufferSize)
        Creates a new Output for writing to an OutputStream with the specified buffer size.
      • UnsafeByteBufferOutput

        public UnsafeByteBufferOutput​(long address,
                                      int size)
        Creates a new Output for writing to a ByteBuffer representing the memory region at the specified address and size. @throws UnsupportedOperationException if creating a ByteBuffer this way is not available.