Class UnsafeOutput

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

    public class UnsafeOutput
    extends Output
    An Output that reads data 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

      • UnsafeOutput

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

        public UnsafeOutput​(int bufferSize,
                            int maxBufferSize)
        Creates a new Output for writing to a byte[].
        Parameters:
        bufferSize - The initial size of the buffer.
        maxBufferSize - If Output.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.
      • UnsafeOutput

        public UnsafeOutput​(byte[] buffer)
        Creates a new Output for writing to a byte[].
        See Also:
        Output.setBuffer(byte[])
      • UnsafeOutput

        public UnsafeOutput​(byte[] buffer,
                            int maxBufferSize)
        Creates a new Output for writing to a byte[].
        See Also:
        Output.setBuffer(byte[], int)
      • UnsafeOutput

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

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