Class UnsafeBytesOutput
- java.lang.Object
-
- org.apache.hugegraph.computer.core.io.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.BytesOutputUse 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()voidclose()longposition()protected voidrequire(int size)protected voidrequire(long position, int size)voidseek(long position)longskip(long bytesToSkip)If you write some thing, and you need to write the serialized byte size first.byte[]toByteArray()voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwrite(org.apache.hugegraph.computer.core.io.RandomAccessInput input, long offset, long length)voidwriteBoolean(boolean v)voidwriteByte(int v)voidwriteBytes(java.lang.String s)voidwriteChar(int v)voidwriteChars(java.lang.String s)voidwriteDouble(double v)voidwriteFixedInt(int v)voidwriteFixedInt(long position, int v)voidwriteFloat(float v)voidwriteInt(int v)voidwriteLong(long v)voidwriteShort(int v)voidwriteUTF(java.lang.String s)
-
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException- Specified by:
writein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Specified by:
writein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeBoolean
public void writeBoolean(boolean v) throws java.io.IOException- Specified by:
writeBooleanin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeByte
public void writeByte(int v) throws java.io.IOException- Specified by:
writeBytein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeShort
public void writeShort(int v) throws java.io.IOException- Specified by:
writeShortin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeChar
public void writeChar(int v) throws java.io.IOException- Specified by:
writeCharin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeInt
public void writeInt(int v) throws java.io.IOException- Specified by:
writeIntin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeLong
public void writeLong(long v) throws java.io.IOException- Specified by:
writeLongin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeFloat
public void writeFloat(float v) throws java.io.IOException- Specified by:
writeFloatin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeDouble
public void writeDouble(double v) throws java.io.IOException- Specified by:
writeDoublein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeBytes
public void writeBytes(java.lang.String s) throws java.io.IOException- Specified by:
writeBytesin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeChars
public void writeChars(java.lang.String s) throws java.io.IOException- Specified by:
writeCharsin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeUTF
public void writeUTF(java.lang.String s) throws java.io.IOException- Specified by:
writeUTFin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
position
public long position()
- Specified by:
positionin interfaceorg.apache.hugegraph.computer.core.io.RandomAccessOutput
-
seek
public void seek(long position) throws java.io.IOException- Specified by:
seekin interfaceorg.apache.hugegraph.computer.core.io.RandomAccessOutput- Throws:
java.io.IOException
-
skip
public long skip(long bytesToSkip) throws java.io.IOExceptionIf 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 ofposition()before and after write the content.- Specified by:
skipin interfaceorg.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:
writein interfaceorg.apache.hugegraph.computer.core.io.RandomAccessOutput- Throws:
java.io.IOException
-
writeFixedInt
public void writeFixedInt(int v) throws java.io.IOException- Specified by:
writeFixedIntin interfaceorg.apache.hugegraph.computer.core.io.RandomAccessOutput- Throws:
java.io.IOException
-
writeFixedInt
public void writeFixedInt(long position, int v) throws java.io.IOException- Specified by:
writeFixedIntin interfaceorg.apache.hugegraph.computer.core.io.RandomAccessOutput- Throws:
java.io.IOException
-
buffer
public byte[] buffer()
- Specified by:
bufferin interfaceorg.apache.hugegraph.computer.core.io.BytesOutput- Returns:
- the internal byte array, can't modify the returned byte array
-
toByteArray
public byte[] toByteArray()
- Specified by:
toByteArrayin interfaceorg.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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-