public interface RandomDataOutput extends ObjectOutput, RandomAccess, BytesCommon
Modifier and Type | Method and Description |
---|---|
int |
addAndGetInt(long offset,
int delta)
Atomically adds the given value to the current value.
|
void |
close()
The same as calling finish();
|
boolean |
compareAndSwapDouble(long offset,
double expected,
double x)
Perform a compare and set operation.
|
boolean |
compareAndSwapInt(long offset,
int expected,
int x)
Perform a compare and set operation.
|
boolean |
compareAndSwapLong(long offset,
long expected,
long x)
Perform a compare and set operation.
|
void |
flush()
Check the end of the stream has not overflowed.
|
int |
getAndAdd(long offset,
int delta)
Atomically adds the given value to the current value.
|
void |
write(byte[] bytes)
Writes to the output stream all the bytes in array
bytes . |
void |
write(byte[] bytes,
int off,
int len)
Writes
len bytes from array bytes , in order, to the output stream. |
void |
write(Byteable byteable)
Copies the contents of a Byteable from the offset for maxSize bytes, moves the position of "this" RandomDataOutput by the maxSize
|
void |
write(ByteBuffer bb)
Copies the contents of a ByteBuffer from the position to the limit.
|
void |
write(char[] data) |
void |
write(char[] data,
int off,
int len) |
void |
write(int b)
Writes to the output stream the eight low-order bits of the argument
b . |
void |
write(long offset,
byte[] bytes)
Writes to the output stream all the bytes in array
bytes . |
void |
write(long offset,
byte[] bytes,
int off,
int len) |
void |
write(long offset,
Bytes bytes) |
void |
write(RandomDataInput bytes)
Copies the contents of a RandomDataInput from the position to the limit.
|
void |
write(RandomDataInput bytes,
long position,
long length)
Copy from one Bytes to another, moves the position of "this" RandomDataOutput by the length.
|
void |
write8bitText(CharSequence s) |
void |
writeBoolean(boolean v)
Writes a
boolean value to this output stream. |
void |
writeBoolean(long offset,
boolean v)
Writes a
boolean value to this output stream. |
void |
writeByte(int v)
Writes to the output stream the eight low- order bits of the argument
v . |
void |
writeByte(long offset,
int b)
Writes to the output stream the eight low-order bits of the argument
b . |
void |
writeBytes(String s)
Writes a string to the output stream.
|
void |
writeChar(int v)
Writes a
char value, which is comprised of two bytes, to the output stream. |
void |
writeChar(long offset,
int v)
Writes a
char value, which is comprised of two bytes, to the output stream. |
void |
writeChars(CharSequence cs)
Writes chars of the given
CharSequence to the bytes, without encoding. |
void |
writeChars(String s)
Writes every character in the string
s , to the output stream, in order, two bytes per character. |
void |
writeCompactDouble(double v)
Writes four or twelve bytes as follow;
|
void |
writeCompactInt(int v)
Writes two or six bytes as follows; Integer.MIN_VALUE => Short.MIN_VALUE, Integer.MAX_VALUE =>
Short.MAX_VALUE, Short.MIN_VALUE+2 to Short.MAX_VALUE-1 => writeShort(x), default =>
writeShort(Short.MIN_VALUE+1; writeInt(x)
|
void |
writeCompactLong(long v)
Writes four or twelve bytes as follows Long.MIN_VALUE => Integer.MIN_VALUE, Long.MAX_VALUE =>
Integer.MAX_VALUE, Integer.MIN_VALUE+2 to Integer.MAX_VALUE-1 => writeInt(x), default =>
writeInt(Integer.MIN_VALUE+1; writeLong(x)
|
void |
writeCompactShort(int v)
Writes one or three bytes as follows; Short.MIN_VALUE => Byte.MIN_VALUE, Short.MAX_VALUE => Byte.MAX_VALUE,
Short.MIN_VALUE+2 to Short.MAX_VALUE-1 => writeByte(x), default => writeByte(Byte.MIN_VALUE+1;
writeShort(x)
|
void |
writeCompactUnsignedInt(long v)
Writes two or six bytes as follows; 0 to (1 << 16) - 2 => writeInt(x), otherwise writeShort(-1);
writeInt(x)
|
void |
writeCompactUnsignedShort(int v)
Writes one or three bytes as follows; 0 to 254 => writeByte(x); otherwise writeByte(255); writeByteShort(x);
|
void |
writeDouble(double v)
Writes a
double value, which is comprised of eight bytes, to the output stream. |
void |
writeDouble(long offset,
double v)
Writes a
double value, which is comprised of eight bytes, to the output stream. |
<E> void |
writeEnum(E e)
Write the object in a form which can be uniquely recreated by readEnum.
|
void |
writeEnum(long offset,
int len,
Object object) |
void |
writeFloat(float v)
Writes a
float value, which is comprised of four bytes, to the output stream. |
void |
writeFloat(long offset,
float v)
Writes a
float value, which is comprised of four bytes, to the output stream. |
<OBJ> void |
writeInstance(Class<OBJ> objClass,
OBJ obj)
Write an object with the assumption that the objClass will be provided when the class is read.
|
void |
writeInt(int v)
Writes an
int value, which is comprised of four bytes, to the output stream. |
void |
writeInt(long offset,
int v)
Writes an
int value, which is comprised of four bytes, to the output stream. |
void |
writeInt24(int v)
Writes an
int value, which is comprised of three bytes, to the output stream. |
void |
writeInt24(long offset,
int v)
Writes an
int value, which is comprised of three bytes, to the output stream. |
void |
writeInt48(long v)
Writes a
long value, which is comprised of eight bytes, to the output stream. |
void |
writeInt48(long offset,
long v)
Writes a
long value, which is comprised of eight bytes, to the output stream. |
<E> void |
writeList(Collection<E> list)
Write an ordered collection of "enumerable objects" (See writeEnum).
|
void |
writeLong(long v)
Writes a
long value, which is comprised of eight bytes, to the output stream. |
void |
writeLong(long offset,
long v)
Writes a
long value, which is comprised of eight bytes, to the output stream. |
<K,V> void |
writeMap(Map<K,V> map)
Write the keys and values of a Map of "enumerable objects" (See writeEnum).
|
void |
writeObject(Object object)
Write an object as either an "enumerable object" or a Serializable/Externalizable object using Java
Serialization.
|
void |
writeObject(Object object,
int start,
int end)
Copy data from an Object from bytes start to end.
|
void |
writeOrderedDouble(long offset,
double v)
Same as writeDouble but include an ordered write barrier.
|
void |
writeOrderedFloat(long offset,
float v)
Same as writeFloat but include an ordered write barrier.
|
void |
writeOrderedInt(int v)
Same as writeInt but include an ordered write barrier.
|
void |
writeOrderedInt(long offset,
int v)
Same as writeInt but include an ordered write barrier.
|
void |
writeOrderedLong(long v)
Same as writeLong but include an ordered write barrier.
|
void |
writeOrderedLong(long offset,
long v)
Same as writeLong but include an ordered write barrier.
|
void |
writeShort(int v)
Writes two bytes to the output stream to represent the value of the argument.
|
void |
writeShort(long offset,
int v)
Writes two bytes to the output stream to represent the value of the argument.
|
void |
writeStopBit(long n)
Stop bit encoding numbers.
|
void |
writeUnsignedByte(int v)
Writes to the output stream the eight low- order bits of the argument
v . |
void |
writeUnsignedByte(long offset,
int v)
Writes to the output stream the eight low- order bits of the argument
v . |
void |
writeUnsignedInt(long v)
Writes an
int value, which is comprised of four bytes, to the output stream. |
void |
writeUnsignedInt(long offset,
long v)
Writes an
int value, which is comprised of four bytes, to the output stream. |
void |
writeUnsignedShort(int v)
Writes two bytes to the output stream to represent the value of the argument.
|
void |
writeUnsignedShort(long offset,
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 string
s . |
void |
writeUTFΔ(CharSequence s)
Write the same encoding as
writeUTF with the following changes. |
void |
writeUTFΔ(long offset,
int maxSize,
CharSequence s)
Write the same encoding as
writeUTF with the following changes. |
Bytes |
zeroOut()
fill the Bytes with zeros, and clear the position.
|
Bytes |
zeroOut(long start,
long end)
fill the Bytes with zeros.
|
Bytes |
zeroOut(long start,
long end,
boolean ifNotZero)
fill the Bytes with zeros, and clear the position, avoiding touching pages unnecessarily
|
alignPositionAddr, byteOrder, capacity, checkEndOfBuffer, clear, finish, flip, inputStream, isFinished, limit, limit, load, objectSerializer, outputStream, position, position, remaining, slice, slice, sliceAsByteBuffer, toDebugString, toDebugString, toHexString, toString
void write(RandomDataInput bytes)
This method transfers the bytes remaining in the given source
buffer into this buffer. If there are more bytes remaining in the
source buffer than in this buffer, that is, if
src.remaining() > remaining(),
then no bytes are transferred and a BufferOverflowException
is thrown.
Otherwise, this method copies n = src.remaining() bytes from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.
In other words, an invocation of this method of the form dst.write(src) has exactly the same effect as the loop
while (src.hasRemaining()) dst.writeByte(src.readByte());
bytes
- to copyvoid write(RandomDataInput bytes, long position, long length)
bytes
- to copyposition
- to copy fromlength
- to copyvoid write(@NotNull Byteable byteable)
byteable
- to copyvoid write(int b)
b
. The 24 high-order bits of
b
are ignored.write
in interface DataOutput
write
in interface ObjectOutput
b
- the byte to be written.void writeByte(int v)
v
. The 24 high-order bits of
v
are ignored. (This means that writeByte
does exactly the same thing as
write
for an integer argument.) The byte written by this method may be read by the
readByte
method of interface DataInput
, which will then return a byte
equal to (byte)v
.writeByte
in interface DataOutput
v
- the byte value to be written.void writeUnsignedByte(int v)
v
. The 24 high-order bits of
v
are ignored. (This means that writeByte
does exactly the same thing as
write
for an integer argument.) The byte written by this method may be read by the
readUnsignedByte
method of interface DataInput
, which will then return a
byte
equal to (byte)v
.v
- the byte value to be written.void writeByte(long offset, int b)
b
. The 24 high-order bits of
b
are ignored.offset
- to write byteb
- the byte to be written.void writeUnsignedByte(long offset, int v)
v
. The 24 high-order bits of
v
are ignored. (This means that writeByte
does exactly the same thing as
write
for an integer argument.) The byte written by this method may be read by the
readUnsignedByte
method of interface DataInput
, which will then return a
byte
equal to v & 0xFF
.offset
- to write bytev
- the unsigned byte value to be written.void write(byte[] bytes)
bytes
. If bytes
is
null
, a NullPointerException
is thrown. If bytes.length
is zero, then no
bytes are written. Otherwise, the byte bytes[0]
is written first, then bytes[1]
, and so
on; the last byte written is bytes[bytes.length-1]
.write
in interface DataOutput
write
in interface ObjectOutput
bytes
- the data.void write(long offset, byte[] bytes)
bytes
. If bytes
is
null
, a NullPointerException
is thrown. If bytes.length
is zero, then no
bytes are written. Otherwise, the byte bytes[0]
is written first, then bytes[1]
, and so
on; the last byte written is bytes[bytes.length-1]
.offset
- to be writtenbytes
- the data.void write(long offset, Bytes bytes)
void write(byte[] bytes, int off, int len)
len
bytes from array bytes
, in order, to the output stream. If
bytes
is null
, a NullPointerException
is thrown. If off
is
negative, or len
is negative, or off+len
is greater than the length of the array
bytes
, then an IndexOutOfBoundsException
is thrown. If len
is zero, then
no bytes are written. Otherwise, the byte bytes[off]
is written first, then
bytes[off+1]
, and so on; the last byte written is bytes[off+len-1]
.write
in interface DataOutput
write
in interface ObjectOutput
bytes
- the data.off
- the start offset in the data.len
- the number of bytes to write.void write(long offset, byte[] bytes, int off, int len)
void write(@NotNull char[] data)
void write(@NotNull char[] data, int off, int len)
void writeBoolean(boolean v)
boolean
value to this output stream. If the argument v
is true
,
the value (byte)1
is written; if v
is false
, the value
(byte)0
is written. The byte written by this method may be read by the readBoolean
method of interface DataInput
, which will then return a boolean
equal to
v
.writeBoolean
in interface DataOutput
v
- the boolean to be written.void writeBoolean(long offset, boolean v)
boolean
value to this output stream. If the argument v
is true
,
the value (byte)1
is written; if v
is false
, the value
(byte)0
is written. The byte written by this method may be read by the readBoolean
method of interface DataInput
, which will then return a boolean
equal to
v
.offset
- to write booleanv
- the boolean to be written.void writeShort(int v)
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
The bytes written by this method may be read by the readShort
method of interface
DataInput
, which will then return a short
equal to (short)v
.
writeShort
in interface DataOutput
v
- the short
value to be written.void writeShort(long offset, int v)
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
The bytes written by this method may be read by the readShort
method of interface
DataInput
, which will then return a short
equal to (short)v
.
offset
- to be written tov
- the short
value to be written.void writeUnsignedShort(int v)
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
The bytes written by this method may be read by the readUnsignedShort
method of interface
RandomDataInput
, which will then return a short
equal to (short)v
.
v
- the unsigned short
value to be written.void writeUnsignedShort(long offset, int v)
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
The bytes written by this method may be read by the readShort
method of interface
RandomDataInput
, which will then return a short
equal to (short)v
.
offset
- to be written tov
- the unsigned short
value to be written.void writeCompactShort(int v)
The bytes written by this method may be read by the readCompactShort
method of interface
RandomDataInput
, which will then return a short
equal to (short)v
.
v
- the short
value to be written.void writeCompactUnsignedShort(int v)
The bytes written by this method may be read by the readCompactUnsignedShort
method of interface
RandomDataInput
, which will then return a short
equal to v & 0xFFFF
.
v
- the unsigned short
value to be written.void writeChar(int v)
char
value, which is comprised of two bytes, to the output stream. The byte values to be
written, in the order shown for big endian machines and the opposite for little endian, are:
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
The bytes written by this method may be read by the readChar
method of interface
DataInput
, which will then return a char
equal to (char)v
.
writeChar
in interface DataOutput
v
- the char
value to be written.void writeChar(long offset, int v)
char
value, which is comprised of two bytes, to the output stream. The byte values to be
written, in the order shown for big endian machines and the opposite for little endian, are:
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
The bytes written by this method may be read by the readChar
method of interface
DataInput
, which will then return a char
equal to (char)v
.
offset
- to be written tov
- the char
value to be written.void writeInt24(int v)
int
value, which is comprised of three bytes, to the output stream. The byte values to be
written, in the order shown for big endian machines and the opposite for little endian, are:
(byte)(0xff & (v >> 16))
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
The bytes written by this method may be read by the readInt24
method of interface
RandomDataInput
, which will then return an int
equal to v
.
v
- the int
value to be written.void writeInt24(long offset, int v)
int
value, which is comprised of three bytes, to the output stream. The byte values to be
written, in the order shown for big endian machines and the opposite for little endian, are:
(byte)(0xff & (v >> 16))
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
The bytes written by this method may be read by the readInt24
method of interface
RandomDataInput
, which will then return an int
equal to v
.
offset
- to be written tov
- the int
value to be written.void writeInt(int v)
int
value, which is comprised of four bytes, to the output stream. The byte values to be
written, in the order shown for big endian machines and the opposite for little endian, 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 interface
DataInput
, which will then return an int
equal to v
.
writeInt
in interface DataOutput
v
- the int
value to be written.void writeInt(long offset, int v)
int
value, which is comprised of four bytes, to the output stream. The byte values to be
written, in the order shown for big endian machines and the opposite for little endian, 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 interface
DataInput
, which will then return an int
equal to v
.
offset
- to be written tov
- the int
value to be written.void writeUnsignedInt(long v)
int
value, which is comprised of four bytes, to the output stream. The byte values to be
written, in the order shown for big endian machines and the opposite for little endian, 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 readUnsignedInt
method of interface
RandomDataInput
, which will then return an long
equal to v &
0xFFFFFFFF
.
v
- the int
value to be written.void writeUnsignedInt(long offset, long v)
int
value, which is comprised of four bytes, to the output stream. The byte values to be
written, in the order shown for big endian machines and the opposite for little endian, 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 readUnsignedInt
method of interface
RandomDataInput
, which will then return an long
equal to v &
0xFFFFFFFF
.
offset
- to be written tov
- the int
value to be written.void writeCompactInt(int v)
The bytes written by this method may be read by the readCompactInt
method of interface
RandomDataInput
, which will then return a int
equal to v
.
v
- the int
value to be written.void writeCompactUnsignedInt(long v)
The bytes written by this method may be read by the readCompactUnsignedInt
method of interface
RandomDataInput
, which will then return a int
equal to v &
0xFFFFFFFF
.
v
- the short
value to be written.void writeOrderedInt(int v)
This is much faster than a volatile write which stalls the pipeline. The data is visible to other threads at the same time.
v
- value to writevoid writeOrderedInt(long offset, int v)
This is much faster than writeVolatileInt
as the volatile write stalls the pipeline. The data is
visible to other threads at the same time.
offset
- to write tov
- value to writeboolean compareAndSwapInt(long offset, int expected, int x)
x
provided the expected
value
is set already. This operation is atomic.offset
- to write to.expected
- to expectx
- to set if expected was foundint getAndAdd(long offset, int delta)
offset
- of the int value to use.delta
- the value to addint addAndGetInt(long offset, int delta)
offset
- of the int value to use.delta
- the value to addvoid writeInt48(long v)
long
value, which is comprised of eight bytes, to the output stream. The byte values to be
written, in the order shown for big endian machines and the opposite for little endian, are:
(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 readInt48
method of interface
RandomDataInput
, which will then return a long
equal to v & ((1L << 48)
- 1)
.
v
- the long
value to be written.void writeInt48(long offset, long v)
long
value, which is comprised of eight bytes, to the output stream. The byte values to be
written, in the order shown for big endian machines and the opposite for little endian, are:
(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 readInt48
method of interface
RandomDataInput
, which will then return a long
equal to v & ((1L << 48)
- 1)
.
offset
- to be written tov
- the long
value to be written.void writeLong(long v)
long
value, which is comprised of eight bytes, to the output stream. The byte values to be
written, in the order shown for big endian machines and the opposite for little endian, 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 interface
DataInput
, which will then return a long
equal to v
.
writeLong
in interface DataOutput
v
- the long
value to be written.void writeLong(long offset, long v)
long
value, which is comprised of eight bytes, to the output stream. The byte values to be
written, in the order shown for big endian machines and the opposite for little endian, 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 interface
DataInput
, which will then return a long
equal to v
.
offset
- to be written tov
- the long
value to be written.void writeCompactLong(long v)
The bytes written by this method may be read by the readCompactLong
method of interface
RandomDataInput
, which will then return a long
equal to v
.
v
- the long
value to be written.void writeOrderedLong(long v)
This is much faster than a volatile write which stalls the pipeline. The data is visible to other threads at the same time.
v
- value to writevoid writeOrderedLong(long offset, long v)
This is much faster than a volatile write which stalls the pipeline. The data is visible to other threads at the same time.
offset
- to be written tov
- value to writeboolean compareAndSwapLong(long offset, long expected, long x)
x
provided the expected
value
is set already. This operation is atomic.offset
- to write to.expected
- to expectx
- to set if expected was foundboolean compareAndSwapDouble(long offset, double expected, double x)
x
provided the expected
value
is set already. This operation is atomic.offset
- to write to.expected
- to expectx
- to set if expected was foundvoid writeStopBit(long n)
n
- the number to writevoid writeFloat(float v)
float
value, which is comprised of four bytes, to the output stream. It does this as if it
first converts this float
value to an int
in exactly the manner of the
Float.floatToIntBits
method and then writes the int
value in exactly the manner of the
writeInt
method. The bytes written by this method may be read by the readFloat
method
of interface DataInput
, which will then return a float
equal to v
.writeFloat
in interface DataOutput
v
- the float
value to be written.void writeFloat(long offset, float v)
float
value, which is comprised of four bytes, to the output stream. It does this as if it
first converts this float
value to an int
in exactly the manner of the
Float.floatToIntBits
method and then writes the int
value in exactly the manner of the
writeInt
method. The bytes written by this method may be read by the readFloat
method
of interface DataInput
, which will then return a float
equal to v
.offset
- to write tov
- the float
value to be written.void writeOrderedFloat(long offset, float v)
This is much faster than a volatile write which stalls the pipeline. The data is visible to other threads at the same time.
offset
- to write tov
- value to writevoid writeDouble(double v)
double
value, which is comprised of eight bytes, to the output stream. It does this as if
it first converts this double
value to a long
in exactly the manner of the
Double.doubleToLongBits
method and then writes the long
value in exactly the manner of
the writeLong
method. The bytes written by this method may be read by the readDouble
method of interface DataInput
, which will then return a double
equal to
v
.writeDouble
in interface DataOutput
v
- the double
value to be written.void writeDouble(long offset, double v)
double
value, which is comprised of eight bytes, to the output stream. It does this as if
it first converts this double
value to a long
in exactly the manner of the
Double.doubleToLongBits
method and then writes the long
value in exactly the manner of
the writeLong
method. The bytes written by this method may be read by the readDouble
method of interface DataInput
, which will then return a double
equal to
v
.offset
- to write tov
- the double
value to be written.void writeCompactDouble(double v)
Writes four or twelve bytes as follow;
if ((float) d == d) {
writeFloat((float) d);
} else {
writeFloat(Float.NaN);
writeDouble(d);
}
The bytes written by this method may be read by the readCompactDouble
method of interface
RandomDataInput
, which will then return a double
equal to v
.v
- the double
value to be written.void writeOrderedDouble(long offset, double v)
This is much faster than a volatile write which stalls the pipeline. The data is visible to other threads at the same time.
offset
- to write tov
- value to writevoid writeBytes(@NotNull String s)
s
, taken in order, one byte
is written to the output stream. If s
is null
, a NullPointerException
is
thrown. If s.length
is zero, then no bytes are written. Otherwise, the character
s[0]
is written first, then s[1]
, and so on; the last character written is
s[s.length-1]
. For each character, one byte is written, the low-order byte, in exactly the manner of
the writeByte
method . The high-order eight bits of each character in the string are ignored.
writeBytes
in interface DataOutput
s
- the string of bytes to be written. Cannot be null.void writeChars(@NotNull String s)
s
, to the output stream, in order, two bytes per character. If
s
is null
, a NullPointerException
is thrown. If s.length
is
zero, then no characters are written. Otherwise, the character s[0]
is written first, then
s[1]
, and so on; the last character written is s[s.length-1]
. For each character, two
bytes are actually written, high-order byte first, in exactly the manner of the writeChar
method.writeChars
in interface DataOutput
s
- the string value to be written. Cannot be null.writeChars(CharSequence)
void writeChars(@NotNull CharSequence cs)
CharSequence
to the bytes, without encoding.cs
- the CharSequence
to be written. Cannot be null.writeChars(String)
void writeUTF(@NotNull String s)
s
. If s
is null
, a NullPointerException
is thrown. Each
character in the string s
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
through uffff
, 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 than 65535
, then a UTFDataFormatException
is thrown. Otherwise, this length
is written to the output stream in exactly the manner of the writeShort
method; after this, the
one-, two-, or three-byte representation of each character in the string s
is written.
The bytes
written by this method may be read by the readUTF
method of interface DataInput
, which
will then return a String
equal to s
.
writeUTF
in interface DataOutput
s
- the string value to be written. Cannot be nullvoid writeUTFΔ(@Nullable CharSequence s) throws IllegalArgumentException
writeUTF
with the following changes. 1) The length is stop bit encoded
i.e. one byte longer for short strings, but is not limited in length. 2) The string can be null.s
- the string value to be written. Can be null.IllegalArgumentException
- if there is not enough space leftvoid writeUTFΔ(long offset, int maxSize, @Nullable CharSequence s) throws IllegalStateException
writeUTF
with the following changes. 1) The length is stop bit encoded
i.e. one byte longer for short strings, but is not limited in length. 2) The string can be null.offset
- to write tomaxSize
- maximum number of bytes to uses
- the string value to be written. Can be null.IllegalStateException
- if the size is too large.void write8bitText(@Nullable CharSequence s)
void write(@NotNull ByteBuffer bb)
This method transfers the bytes remaining in the given source
buffer into this buffer. If there are more bytes remaining in the
source buffer than in this buffer, that is, if
src.remaining() > remaining(),
then no bytes are transferred and a BufferOverflowException
is thrown.
Otherwise, this method copies n = src.remaining() bytes from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.
In other words, an invocation of this method of the form dst.write(src) has exactly the same effect as the loop
while (src.hasRemaining()) dst.writeByte(src.get());
bb
- to copy.<E> void writeEnum(@Nullable E e)
valueOf(String)
method.E
- element classe
- to enumerate<E> void writeList(@NotNull Collection<E> list)
writeEnum
All the elements must be of the same type.
This can be read by the readList
method of RandomInputStream
and the reader must know
the type of each element. You can send the class first by using writeEnum
of the element class
E
- the class of the list elementslist
- to be written<K,V> void writeMap(@NotNull Map<K,V> map)
writeEnum
for each key and value. All the keys must be of the
same type. All values must be of the same type.K
- the class of the map keysV
- the class of the map valuesmap
- to write outvoid writeObject(@Nullable Object object)
writeObject
in interface ObjectOutput
object
- to write<OBJ> void writeInstance(@NotNull Class<OBJ> objClass, @NotNull OBJ obj)
OBJ
- the class of the object to writeobjClass
- class to writeobj
- to writevoid writeObject(Object object, int start, int end)
object
- to copy fromstart
- first byte inclusiveend
- last byte exclusive.Bytes zeroOut()
Bytes zeroOut(long start, long end)
start
- first byte to zero outend
- the first byte after the last to zero out (exclusive bound)Bytes zeroOut(long start, long end, boolean ifNotZero)
start
- first byte to zero outend
- the first byte after the last to zero out (exclusive bound)ifNotZero
- only set to zero after checking the value is not zero.void flush()
flush
in interface ObjectOutput
void close()
close
in interface AutoCloseable
close
in interface ObjectOutput
void writeEnum(long offset, int len, Object object)
Copyright © 2019. All rights reserved.