Class UnsafeBytesOutput

  • All Implemented Interfaces:
    java.io.Closeable, java.io.DataOutput, java.lang.AutoCloseable, org.apache.hugegraph.computer.core.io.BytesOutput, org.apache.hugegraph.computer.core.io.RandomAccessOutput
    Direct Known Subclasses:
    AbstractBufferedFileOutput, BufferedStreamOutput

    public class UnsafeBytesOutput
    extends java.lang.Object
    implements org.apache.hugegraph.computer.core.io.BytesOutput
    Use unsafe method to write the value to the buffer to improve the write performance. The buffer is auto extendable.
    • Constructor Summary

      Constructors 
      Constructor Description
      UnsafeBytesOutput​(int size)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] buffer()  
      void close()  
      long position()  
      protected void require​(int size)  
      protected void require​(long position, int size)  
      void seek​(long position)  
      long skip​(long bytesToSkip)
      If you write some thing, and you need to write the serialized byte size first.
      byte[] toByteArray()  
      void write​(byte[] b)  
      void write​(byte[] b, int off, int len)  
      void write​(int b)  
      void write​(org.apache.hugegraph.computer.core.io.RandomAccessInput input, long offset, long length)  
      void writeBoolean​(boolean v)  
      void writeByte​(int v)  
      void writeBytes​(java.lang.String s)  
      void writeChar​(int v)  
      void writeChars​(java.lang.String s)  
      void writeDouble​(double v)  
      void writeFixedInt​(int v)  
      void writeFixedInt​(long position, int v)  
      void writeFloat​(float v)  
      void writeInt​(int v)  
      void writeLong​(long v)  
      void writeShort​(int v)  
      void writeUTF​(java.lang.String s)  
      • Methods inherited from class java.lang.Object

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

      • UnsafeBytesOutput

        public UnsafeBytesOutput​(int size)
    • Method Detail

      • write

        public void write​(int b)
                   throws java.io.IOException
        Specified by:
        write in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] b)
                   throws java.io.IOException
        Specified by:
        write in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Specified by:
        write in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeBoolean

        public void writeBoolean​(boolean v)
                          throws java.io.IOException
        Specified by:
        writeBoolean in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeByte

        public void writeByte​(int v)
                       throws java.io.IOException
        Specified by:
        writeByte in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeShort

        public void writeShort​(int v)
                        throws java.io.IOException
        Specified by:
        writeShort in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeChar

        public void writeChar​(int v)
                       throws java.io.IOException
        Specified by:
        writeChar in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeInt

        public void writeInt​(int v)
                      throws java.io.IOException
        Specified by:
        writeInt in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeLong

        public void writeLong​(long v)
                       throws java.io.IOException
        Specified by:
        writeLong in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeFloat

        public void writeFloat​(float v)
                        throws java.io.IOException
        Specified by:
        writeFloat in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeDouble

        public void writeDouble​(double v)
                         throws java.io.IOException
        Specified by:
        writeDouble in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeBytes

        public void writeBytes​(java.lang.String s)
                        throws java.io.IOException
        Specified by:
        writeBytes in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeChars

        public void writeChars​(java.lang.String s)
                        throws java.io.IOException
        Specified by:
        writeChars in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeUTF

        public void writeUTF​(java.lang.String s)
                      throws java.io.IOException
        Specified by:
        writeUTF in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • position

        public long position()
        Specified by:
        position in interface org.apache.hugegraph.computer.core.io.RandomAccessOutput
      • seek

        public void seek​(long position)
                  throws java.io.IOException
        Specified by:
        seek in interface org.apache.hugegraph.computer.core.io.RandomAccessOutput
        Throws:
        java.io.IOException
      • skip

        public long skip​(long bytesToSkip)
                  throws java.io.IOException
        If you write some thing, and you need to write the serialized byte size first. If the byte size is unknown when write, you can skip 4 bytes (size of int)first, after write out the content, get the serialized byte size and calls writeInt(int position, int v) to write the int at skipped position. The serialized byte size can be get by the difference of position() before and after write the content.
        Specified by:
        skip in interface org.apache.hugegraph.computer.core.io.RandomAccessOutput
        Returns:
        the position before skip.
        Throws:
        java.io.IOException
      • write

        public void write​(org.apache.hugegraph.computer.core.io.RandomAccessInput input,
                          long offset,
                          long length)
                   throws java.io.IOException
        Specified by:
        write in interface org.apache.hugegraph.computer.core.io.RandomAccessOutput
        Throws:
        java.io.IOException
      • writeFixedInt

        public void writeFixedInt​(int v)
                           throws java.io.IOException
        Specified by:
        writeFixedInt in interface org.apache.hugegraph.computer.core.io.RandomAccessOutput
        Throws:
        java.io.IOException
      • writeFixedInt

        public void writeFixedInt​(long position,
                                  int v)
                           throws java.io.IOException
        Specified by:
        writeFixedInt in interface org.apache.hugegraph.computer.core.io.RandomAccessOutput
        Throws:
        java.io.IOException
      • buffer

        public byte[] buffer()
        Specified by:
        buffer in interface org.apache.hugegraph.computer.core.io.BytesOutput
        Returns:
        the internal byte array, can't modify the returned byte array
      • toByteArray

        public byte[] toByteArray()
        Specified by:
        toByteArray in interface org.apache.hugegraph.computer.core.io.BytesOutput
        Returns:
        Copied byte array.
      • require

        protected void require​(int size)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • require

        protected void require​(long position,
                               int size)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException