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 long
bytesWriten()
Return how many bytes has been written.void
close()
void
finishSetting()
Finish setting, shrink vector size to offset.FFIByteVector
getVector()
void
reset()
Reset actually reset the write position, the size kept unchanged.void
resize(long size)
void
write(int b)
Writes the specified byte to this output stream.void
writeBoolean(boolean v)
Writes aboolean
value to this output stream.void
writeByte(int v)
Writes to the output stream the eight low- order bits of the argumentv
.void
writeBytes(StringView s)
void
writeBytes(String s)
Writes a string to the output stream.void
writeChar(int v)
Writes achar
value, which is comprised of two bytes, to the output stream.void
writeChars(String s)
Writes every character in the strings
, to the output stream, in order, two bytes per character.void
writeDouble(double v)
Writes adouble
value, which is comprised of eight bytes, to the output stream.void
writeFloat(float v)
Writes afloat
value, which is comprised of four bytes, to the output stream.void
writeInt(int v)
Writes anint
value, which is comprised of four bytes, to the output stream.void
writeInt(int index, int v)
void
writeLong(int index, long v)
void
writeLong(long v)
Writes along
value, which is comprised of eight bytes, to the output stream.void
writeShort(int v)
Writes two bytes to the output stream to represent the value of the argument.void
writeUTF(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
-
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 IOException
Writes aboolean
value to this output stream. If the argumentv
istrue
, the value(byte)1
is written; ifv
isfalse
, the value(byte)0
is written. The byte written by this method may be read by thereadBoolean
method of interfaceDataInput
, which will then return aboolean
equal tov
.- Specified by:
writeBoolean
in interfaceDataOutput
- Parameters:
v
- the boolean to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeByte
public void writeByte(int v) throws IOException
Writes to the output stream the eight low- order bits of the argumentv
. The 24 high-order bits ofv
are ignored. (This means thatwriteByte
does exactly the same thing aswrite
for an integer argument.) The byte written by this method may be read by thereadByte
method of interfaceDataInput
, which will then return abyte
equal to(byte)v
.- Specified by:
writeByte
in interfaceDataOutput
- Parameters:
v
- the byte value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeShort
public void writeShort(int v) throws IOException
Writes 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
readShort
method of interfaceDataInput
, which will then return ashort
equal to(short)v
.- Specified by:
writeShort
in interfaceDataOutput
- Parameters:
v
- theshort
value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeChar
public void writeChar(int v) throws IOException
Writes achar
value, 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
readChar
method of interfaceDataInput
, which will then return achar
equal to(char)v
.- Specified by:
writeChar
in interfaceDataOutput
- Parameters:
v
- thechar
value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeInt
public void writeInt(int v) throws IOException
Writes anint
value, 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
readInt
method of interfaceDataInput
, which will then return anint
equal tov
.- Specified by:
writeInt
in interfaceDataOutput
- Parameters:
v
- theint
value 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 IOException
Writes along
value, 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
readLong
method of interfaceDataInput
, which will then return along
equal tov
.- Specified by:
writeLong
in interfaceDataOutput
- Parameters:
v
- thelong
value 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 IOException
Writes afloat
value, which is comprised of four bytes, to the output stream. It does this as if it first converts thisfloat
value to anint
in exactly the manner of theFloat.floatToIntBits
method and then writes theint
value in exactly the manner of thewriteInt
method. The bytes written by this method may be read by thereadFloat
method of interfaceDataInput
, which will then return afloat
equal tov
.- Specified by:
writeFloat
in interfaceDataOutput
- Parameters:
v
- thefloat
value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeDouble
public void writeDouble(double v) throws IOException
Writes adouble
value, which is comprised of eight bytes, to the output stream. It does this as if it first converts thisdouble
value to along
in exactly the manner of theDouble.doubleToLongBits
method and then writes thelong
value in exactly the manner of thewriteLong
method. The bytes written by this method may be read by thereadDouble
method of interfaceDataInput
, which will then return adouble
equal tov
.- Specified by:
writeDouble
in interfaceDataOutput
- Parameters:
v
- thedouble
value 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. Ifs
isnull
, aNullPointerException
is thrown.If
s.length
is 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 thewriteByte
method . The high-order eight bits of each character in the string are ignored.- Specified by:
writeBytes
in 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. Ifs
isnull
, aNullPointerException
is thrown. Ifs.length
is 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 thewriteChar
method.- Specified by:
writeChars
in 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
. Ifs
isnull
, aNullPointerException
is thrown. Each character in the strings
is converted to a group of one, two, or three bytes, depending on the value of the character.If a character
c
is in the range\u0001
through\u007f
, it is represented by one byte:(byte)c
If a character
c
is\u0000
or is in the range\u0080
through\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
c
is in the range\u0800
throughuffff
, 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
s
is calculated. If this number is larger than65535
, then aUTFDataFormatException
is thrown. Otherwise, this length is written to the output stream in exactly the manner of thewriteShort
method; after this, the one-, two-, or three-byte representation of each character in the strings
is written.The bytes written by this method may be read by the
readUTF
method of interfaceDataInput
, which will then return aString
equal tos
.- Specified by:
writeUTF
in interfaceDataOutput
- Parameters:
s
- the string value to be written.- Throws:
IOException
- if an I/O error occurs.
-
write
public void write(int b) throws IOException
Writes the specified byte to this output stream. The general contract forwrite
is 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 ofb
are ignored.Subclasses of
OutputStream
must provide an implementation for this method.- Specified by:
write
in interfaceDataOutput
- Specified by:
write
in classOutputStream
- Parameters:
b
- thebyte
.- Throws:
IOException
- if an I/O error occurs. In particular, anIOException
may be thrown if the output stream has been closed.
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
-