Class DataOutputBuffer

  • All Implemented Interfaces:
    java.io.Closeable, java.io.DataOutput, java.io.Flushable, java.lang.AutoCloseable, DataOutputPlus
    Direct Known Subclasses:
    DataOutputBufferFixed, SafeMemoryWriter

    public class DataOutputBuffer
    extends BufferedDataOutputStreamPlus
    An implementation of the DataOutputStream interface using a FastByteArrayOutputStream and exposing its buffer so copies can be avoided. This class is completely thread unsafe.
    • Field Detail

      • scratchBuffer

        public static final io.netty.util.concurrent.FastThreadLocal<DataOutputBuffer> scratchBuffer
        Scratch buffers used mostly for serializing in memory. It's important to call #close() when finished to keep the memory overhead from being too large in the system.
    • Constructor Detail

      • DataOutputBuffer

        public DataOutputBuffer()
      • DataOutputBuffer

        public DataOutputBuffer​(int size)
      • DataOutputBuffer

        public DataOutputBuffer​(java.nio.ByteBuffer buffer)
    • Method Detail

      • expandToFit

        protected void expandToFit​(long count)
      • setBuffer

        protected void setBuffer​(java.nio.ByteBuffer newBuffer)
      • clear

        public void clear()
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class BufferedDataOutputStreamPlus
      • buffer

        public java.nio.ByteBuffer buffer()
      • buffer

        public java.nio.ByteBuffer buffer​(boolean duplicate)
      • unsafeGetBufferAndFlip

        public java.nio.ByteBuffer unsafeGetBufferAndFlip()
        Gets the underlying ByteBuffer and calls ByteBuffer.flip(). This method is "unsafe" in the sense that it returns the underlying buffer, which may be modified by other methods after calling this method (or cleared on close()). If the calling logic knows that no new calls to this object will happen after calling this method, then this method can avoid the copying done in asNewBuffer(), and buffer().
      • getData

        public byte[] getData()
      • getLength

        public int getLength()
      • hasPosition

        public boolean hasPosition()
        Description copied from interface: DataOutputPlus
        If the implementation supports providing a position, this method returns true, otherwise false.
      • position

        public long position()
        Description copied from interface: DataOutputPlus
        Returns the current position of the underlying target like a file-pointer or the position withing a buffer. Not every implementation may support this functionality. Whether or not this functionality is supported can be checked via the DataOutputPlus.hasPosition().
      • asNewBuffer

        public java.nio.ByteBuffer asNewBuffer()
      • toByteArray

        public byte[] toByteArray()
      • asString

        public java.lang.String asString()