Class BufferedStreamOutput
- java.lang.Object
-
- org.apache.hugegraph.computer.core.io.UnsafeBytesOutput
-
- org.apache.hugegraph.computer.core.io.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.
-
-
Constructor Summary
Constructors Constructor Description BufferedStreamOutput(java.io.OutputStream output)BufferedStreamOutput(java.io.OutputStream output, int bufferCapacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()longposition()protected voidrequire(int size)voidseek(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.longskip(long bytesToSkip)If you write some thing, and you need to write the serialized byte size first.voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwriteFixedInt(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 org.apache.hugegraph.computer.core.io.UnsafeBytesOutput
buffer, require, toByteArray, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFixedInt, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
-
-
-
Method Detail
-
write
public void write(byte[] b) throws java.io.IOException- Specified by:
writein interfacejava.io.DataOutput- Overrides:
writein classUnsafeBytesOutput- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Specified by:
writein interfacejava.io.DataOutput- Overrides:
writein classUnsafeBytesOutput- Throws:
java.io.IOException
-
position
public long position()
- Specified by:
positionin interfaceorg.apache.hugegraph.computer.core.io.RandomAccessOutput- Overrides:
positionin classUnsafeBytesOutput
-
seek
public void seek(long position) throws java.io.IOExceptionThe 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:
seekin interfaceorg.apache.hugegraph.computer.core.io.RandomAccessOutput- Overrides:
seekin classUnsafeBytesOutput- Throws:
java.io.IOException
-
skip
public long skip(long bytesToSkip) throws java.io.IOExceptionDescription copied from class:UnsafeBytesOutputIf 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 ofUnsafeBytesOutput.position()before and after write the content.- Specified by:
skipin interfaceorg.apache.hugegraph.computer.core.io.RandomAccessOutput- Overrides:
skipin classUnsafeBytesOutput- Returns:
- the position before skip.
- Throws:
java.io.IOException
-
writeFixedInt
public void writeFixedInt(long position, int v) throws java.io.IOExceptionThe 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:
writeFixedIntin interfaceorg.apache.hugegraph.computer.core.io.RandomAccessOutput- Overrides:
writeFixedIntin classUnsafeBytesOutput- Throws:
java.io.IOException
-
require
protected void require(int size) throws java.io.IOException- Overrides:
requirein classUnsafeBytesOutput- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classUnsafeBytesOutput- Throws:
java.io.IOException
-
-