Class FFIByteVectorOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- com.alibaba.graphscope.serialization.FFIByteVectorOutputStream
-
- All Implemented Interfaces:
Closeable,DataOutput,Flushable,AutoCloseable
public class FFIByteVectorOutputStream extends OutputStream implements DataOutput
-
-
Constructor Summary
Constructors Constructor Description FFIByteVectorOutputStream()FFIByteVectorOutputStream(FFIByteVector vector)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longbytesWriten()Return how many bytes has been written.voidclose()voidfinishSetting()Finish setting, shrink vector size to offset.FFIByteVectorgetVector()voidreset()Reset actually reset the write position, the size kept unchanged.voidresize(long size)voidwrite(int b)Writes the specified byte to this output stream.voidwriteBoolean(boolean v)Writes abooleanvalue to this output stream.voidwriteByte(int v)Writes to the output stream the eight low- order bits of the argumentv.voidwriteBytes(StringView s)voidwriteBytes(String s)Writes a string to the output stream.voidwriteChar(int v)Writes acharvalue, which is comprised of two bytes, to the output stream.voidwriteChars(String s)Writes every character in the strings, to the output stream, in order, two bytes per character.voidwriteDouble(double v)Writes adoublevalue, which is comprised of eight bytes, to the output stream.voidwriteFloat(float v)Writes afloatvalue, which is comprised of four bytes, to the output stream.voidwriteInt(int v)Writes anintvalue, which is comprised of four bytes, to the output stream.voidwriteInt(int index, int v)voidwriteLong(int index, long v)voidwriteLong(long v)Writes alongvalue, which is comprised of eight bytes, to the output stream.voidwriteShort(int v)Writes two bytes to the output stream to represent the value of the argument.voidwriteUTF(String s)Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the strings.-
Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write, write
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.io.DataOutput
write, write
-
-
-
-
Constructor Detail
-
FFIByteVectorOutputStream
public FFIByteVectorOutputStream()
-
FFIByteVectorOutputStream
public FFIByteVectorOutputStream(FFIByteVector vector)
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream
-
resize
public void resize(long size)
-
reset
public void reset()
Reset actually reset the write position, the size kept unchanged.
-
getVector
public FFIByteVector getVector()
-
bytesWriten
public long bytesWriten()
Return how many bytes has been written.- Returns:
-
finishSetting
public void finishSetting()
Finish setting, shrink vector size to offset.
-
writeBoolean
public void writeBoolean(boolean v) throws IOExceptionWrites abooleanvalue to this output stream. If the argumentvistrue, the value(byte)1is written; ifvisfalse, the value(byte)0is written. The byte written by this method may be read by thereadBooleanmethod of interfaceDataInput, which will then return abooleanequal tov.- Specified by:
writeBooleanin interfaceDataOutput- Parameters:
v- the boolean to be written.- Throws:
IOException- if an I/O error occurs.
-
writeByte
public void writeByte(int v) throws IOExceptionWrites to the output stream the eight low- order bits of the argumentv. The 24 high-order bits ofvare ignored. (This means thatwriteBytedoes exactly the same thing aswritefor an integer argument.) The byte written by this method may be read by thereadBytemethod of interfaceDataInput, which will then return abyteequal to(byte)v.- Specified by:
writeBytein interfaceDataOutput- Parameters:
v- the byte value to be written.- Throws:
IOException- if an I/O error occurs.
-
writeShort
public void writeShort(int v) throws IOExceptionWrites two bytes to the output stream to represent the value of the argument. The byte values to be written, in the order shown, are:(byte)(0xff & (v >> 8)) (byte)(0xff & v)The bytes written by this method may be read by the
readShortmethod of interfaceDataInput, which will then return ashortequal to(short)v.- Specified by:
writeShortin interfaceDataOutput- Parameters:
v- theshortvalue to be written.- Throws:
IOException- if an I/O error occurs.
-
writeChar
public void writeChar(int v) throws IOExceptionWrites acharvalue, which is comprised of two bytes, to the output stream. The byte values to be written, in the order shown, are:(byte)(0xff & (v >> 8)) (byte)(0xff & v)The bytes written by this method may be read by the
readCharmethod of interfaceDataInput, which will then return acharequal to(char)v.- Specified by:
writeCharin interfaceDataOutput- Parameters:
v- thecharvalue to be written.- Throws:
IOException- if an I/O error occurs.
-
writeInt
public void writeInt(int v) throws IOExceptionWrites anintvalue, which is comprised of four bytes, to the output stream. The byte values to be written, in the order shown, are:(byte)(0xff & (v >> 24)) (byte)(0xff & (v >> 16)) (byte)(0xff & (v >> 8)) (byte)(0xff & v)The bytes written by this method may be read by the
readIntmethod of interfaceDataInput, which will then return anintequal tov.- Specified by:
writeIntin interfaceDataOutput- Parameters:
v- theintvalue to be written.- Throws:
IOException- if an I/O error occurs.
-
writeInt
public void writeInt(int index, int v)
-
writeLong
public void writeLong(long v) throws IOExceptionWrites alongvalue, which is comprised of eight bytes, to the output stream. The byte values to be written, in the order shown, are:(byte)(0xff & (v >> 56)) (byte)(0xff & (v >> 48)) (byte)(0xff & (v >> 40)) (byte)(0xff & (v >> 32)) (byte)(0xff & (v >> 24)) (byte)(0xff & (v >> 16)) (byte)(0xff & (v >> 8)) (byte)(0xff & v)The bytes written by this method may be read by the
readLongmethod of interfaceDataInput, which will then return alongequal tov.- Specified by:
writeLongin interfaceDataOutput- Parameters:
v- thelongvalue to be written.- Throws:
IOException- if an I/O error occurs.
-
writeLong
public void writeLong(int index, long v)
-
writeFloat
public void writeFloat(float v) throws IOExceptionWrites afloatvalue, which is comprised of four bytes, to the output stream. It does this as if it first converts thisfloatvalue to anintin exactly the manner of theFloat.floatToIntBitsmethod and then writes theintvalue in exactly the manner of thewriteIntmethod. The bytes written by this method may be read by thereadFloatmethod of interfaceDataInput, which will then return afloatequal tov.- Specified by:
writeFloatin interfaceDataOutput- Parameters:
v- thefloatvalue to be written.- Throws:
IOException- if an I/O error occurs.
-
writeDouble
public void writeDouble(double v) throws IOExceptionWrites adoublevalue, which is comprised of eight bytes, to the output stream. It does this as if it first converts thisdoublevalue to alongin exactly the manner of theDouble.doubleToLongBitsmethod and then writes thelongvalue in exactly the manner of thewriteLongmethod. The bytes written by this method may be read by thereadDoublemethod of interfaceDataInput, which will then return adoubleequal tov.- Specified by:
writeDoublein interfaceDataOutput- Parameters:
v- thedoublevalue to be written.- Throws:
IOException- if an I/O error occurs.
-
writeBytes
public void writeBytes(String s) throws IOException
Writes a string to the output stream. For every character in the strings, taken in order, one byte is written to the output stream. Ifsisnull, aNullPointerExceptionis thrown.If
s.lengthis zero, then no bytes are written. Otherwise, the characters[0]is written first, thens[1], and so on; the last character written iss[s.length-1]. For each character, one byte is written, the low-order byte, in exactly the manner of thewriteBytemethod . The high-order eight bits of each character in the string are ignored.- Specified by:
writeBytesin interfaceDataOutput- Parameters:
s- the string of bytes to be written.- Throws:
IOException- if an I/O error occurs.
-
writeBytes
public void writeBytes(StringView s) throws IOException
- Throws:
IOException
-
writeChars
public void writeChars(String s) throws IOException
Writes every character in the strings, to the output stream, in order, two bytes per character. Ifsisnull, aNullPointerExceptionis thrown. Ifs.lengthis zero, then no characters are written. Otherwise, the characters[0]is written first, thens[1], and so on; the last character written iss[s.length-1]. For each character, two bytes are actually written, high-order byte first, in exactly the manner of thewriteCharmethod.- Specified by:
writeCharsin interfaceDataOutput- Parameters:
s- the string value to be written.- Throws:
IOException- if an I/O error occurs.
-
writeUTF
public void writeUTF(String s) throws IOException
Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the strings. Ifsisnull, aNullPointerExceptionis thrown. Each character in the stringsis converted to a group of one, two, or three bytes, depending on the value of the character.If a character
cis in the range\u0001through\u007f, it is represented by one byte:(byte)c
If a character
cis\u0000or is in the range\u0080through\u07ff, then it is represented by two bytes, to be written in the order shown:(byte)(0xc0 | (0x1f & (c >> 6))) (byte)(0x80 | (0x3f & c))If a character
cis in the range\u0800throughuffff, then it is represented by three bytes, to be written in the order shown:(byte)(0xe0 | (0x0f & (c >> 12))) (byte)(0x80 | (0x3f & (c >> 6))) (byte)(0x80 | (0x3f & c))First, the total number of bytes needed to represent all the characters of
sis calculated. If this number is larger than65535, then aUTFDataFormatExceptionis thrown. Otherwise, this length is written to the output stream in exactly the manner of thewriteShortmethod; after this, the one-, two-, or three-byte representation of each character in the stringsis written.The bytes written by this method may be read by the
readUTFmethod of interfaceDataInput, which will then return aStringequal tos.- Specified by:
writeUTFin interfaceDataOutput- Parameters:
s- the string value to be written.- Throws:
IOException- if an I/O error occurs.
-
write
public void write(int b) throws IOExceptionWrites the specified byte to this output stream. The general contract forwriteis that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argumentb. The 24 high-order bits ofbare ignored.Subclasses of
OutputStreammust provide an implementation for this method.- Specified by:
writein interfaceDataOutput- Specified by:
writein classOutputStream- Parameters:
b- thebyte.- Throws:
IOException- if an I/O error occurs. In particular, anIOExceptionmay be thrown if the output stream has been closed.
-
-