Class DataOutputSerializer

    • Constructor Detail

      • DataOutputSerializer

        public DataOutputSerializer​(int startSize)
    • Method Detail

      • wrapAsByteBuffer

        public ByteBuffer wrapAsByteBuffer()
      • getSharedBuffer

        public byte[] getSharedBuffer()
        Gets a reference to the internal byte buffer. This buffer may be larger than the actual serialized data. Only the bytes from zero to length() are valid. The buffer will also be overwritten with the next write calls.

        This method is useful when trying to avid byte copies, but should be used carefully.

        Returns:
        A reference to the internal shared and reused buffer.
      • getCopyOfBuffer

        public byte[] getCopyOfBuffer()
        Gets a copy of the buffer that has the right length for the data serialized so far. The returned buffer is an exclusive copy and can be safely used without being overwritten by future write calls to this serializer.

        This method is equivalent to Arrays.copyOf(getSharedBuffer(), length());

        Returns:
        A non-shared copy of the serialization buffer.
      • clear

        public void clear()
      • length

        public int length()
      • write

        public void write​(MemorySegment segment,
                          int off,
                          int len)
                   throws IOException
        Description copied from interface: MemorySegmentWritable
        Writes len bytes from memory segment segment starting at offset off, in order, to the output.
        Specified by:
        write in interface MemorySegmentWritable
        Parameters:
        segment - memory segment to copy the bytes from.
        off - the start offset in the memory segment.
        len - The number of bytes to copy.
        Throws:
        IOException - if an I/O error occurs.
      • writeLongUTF

        public void writeLongUTF​(String str)
                          throws IOException
        Similar to writeUTF(String). The size is only limited by the maximum java array size of the buffer.
        Parameters:
        str - the string value to be written.
        Throws:
        IOException - if an I/O error occurs.
      • skipBytesToWrite

        public void skipBytesToWrite​(int numBytes)
                              throws IOException
        Description copied from interface: DataOutputView
        Skips numBytes bytes memory. If some program reads the memory that was skipped over, the results are undefined.
        Specified by:
        skipBytesToWrite in interface DataOutputView
        Parameters:
        numBytes - The number of bytes to skip.
        Throws:
        IOException - Thrown, if any I/O related problem occurred such that the view could not be advanced to the desired position.
      • write

        public void write​(DataInputView source,
                          int numBytes)
                   throws IOException
        Description copied from interface: DataOutputView
        Copies numBytes bytes from the source to this view.
        Specified by:
        write in interface DataOutputView
        Parameters:
        source - The source to copy the bytes from.
        numBytes - The number of bytes to copy.
        Throws:
        IOException - Thrown, if any I/O related problem occurred, such that either the input view could not be read, or the output could not be written.
      • setPosition

        public void setPosition​(int position)
      • setPositionUnsafe

        public void setPositionUnsafe​(int position)