Class BufferedStreamOutput

  • 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

    public class BufferedStreamOutput
    extends UnsafeBytesOutput
    This is used to buffer and output the buffer to output stream when buffer is full.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      long position()  
      protected void require​(int size)  
      void seek​(long position)
      The valid range of position is [the output position correspond to buffer start, the output position correspond to the current position], it can't seek to the position before the buffer or after the current position.
      long skip​(long bytesToSkip)
      If you write some thing, and you need to write the serialized byte size first.
      void write​(byte[] b)  
      void write​(byte[] b, int off, int len)  
      void writeFixedInt​(long position, int v)
      The valid range of position is [the output position correspond to buffer start, the output position correspond to the current position - Constants.INT_LEN], it can't write data to the position before the buffer or after the current position.
      • Methods inherited from class java.lang.Object

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

      • BufferedStreamOutput

        public BufferedStreamOutput​(java.io.OutputStream output)
      • BufferedStreamOutput

        public BufferedStreamOutput​(java.io.OutputStream output,
                                    int bufferCapacity)
    • Method Detail

      • write

        public void write​(byte[] b)
                   throws java.io.IOException
        Specified by:
        write in interface java.io.DataOutput
        Overrides:
        write in class UnsafeBytesOutput
        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
        Overrides:
        write in class UnsafeBytesOutput
        Throws:
        java.io.IOException
      • position

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

        public void seek​(long position)
                  throws java.io.IOException
        The valid range of position is [the output position correspond to buffer start, the output position correspond to the current position], it can't seek to the position before the buffer or after the current position.
        Specified by:
        seek in interface org.apache.hugegraph.computer.core.io.RandomAccessOutput
        Overrides:
        seek in class UnsafeBytesOutput
        Throws:
        java.io.IOException
      • skip

        public long skip​(long bytesToSkip)
                  throws java.io.IOException
        Description copied from class: UnsafeBytesOutput
        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 UnsafeBytesOutput.position() before and after write the content.
        Specified by:
        skip in interface org.apache.hugegraph.computer.core.io.RandomAccessOutput
        Overrides:
        skip in class UnsafeBytesOutput
        Returns:
        the position before skip.
        Throws:
        java.io.IOException
      • writeFixedInt

        public void writeFixedInt​(long position,
                                  int v)
                           throws java.io.IOException
        The valid range of position is [the output position correspond to buffer start, the output position correspond to the current position - Constants.INT_LEN], it can't write data to the position before the buffer or after the current position.
        Specified by:
        writeFixedInt in interface org.apache.hugegraph.computer.core.io.RandomAccessOutput
        Overrides:
        writeFixedInt in class UnsafeBytesOutput
        Throws:
        java.io.IOException
      • require

        protected void require​(int size)
                        throws java.io.IOException
        Overrides:
        require in class UnsafeBytesOutput
        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
        Overrides:
        close in class UnsafeBytesOutput
        Throws:
        java.io.IOException