public abstract class WrappedBytes<B extends Bytes> extends Object implements Bytes
Modifier | Constructor and Description |
---|---|
protected |
WrappedBytes(B wrapped) |
Modifier and Type | Method and Description |
---|---|
int |
addAndGetInt(long offset,
int delta)
Atomically adds the given value to the current value.
|
double |
addAtomicDouble(long offset,
double d) |
float |
addAtomicFloat(long offset,
float f) |
int |
addAtomicInt(long offset,
int i) |
long |
addAtomicLong(long offset,
long l) |
byte |
addByte(long offset,
byte b) |
double |
addDouble(long offset,
double d) |
float |
addFloat(long offset,
float f) |
int |
addInt(long offset,
int i) |
long |
addLong(long offset,
long i) |
long |
address() |
short |
addShort(long offset,
short s) |
int |
addUnsignedByte(long offset,
int i) |
long |
addUnsignedInt(long offset,
long i) |
int |
addUnsignedShort(long offset,
int i) |
void |
alignPositionAddr(int alignment)
Align the position address to a power of 2.
|
ByteStringAppender |
append(boolean b)
Writes "true" or "false".
|
ByteStringAppender |
append(char c) |
ByteStringAppender |
append(CharSequence s) |
ByteStringAppender |
append(CharSequence s,
int start,
int end) |
ByteStringAppender |
append(double d) |
ByteStringAppender |
append(double d,
int precision) |
ByteStringAppender |
append(Enum value) |
ByteStringAppender |
append(int i) |
<E> ByteStringAppender |
append(Iterable<E> list,
CharSequence separator) |
ByteStringAppender |
append(long l) |
ByteStringAppender |
append(long l,
int base) |
ByteStringAppender |
append(MutableDecimal md) |
ByteStringAppender |
appendDateMillis(long timeInMS) |
ByteStringAppender |
appendDateTimeMillis(long timeInMS) |
ByteStringAppender |
appendTimeMillis(long timeInMS) |
CharSequence |
asString()
Dump the contents of Bytes as a CharSequence
|
void |
asString(Appendable appendable)
Dump the contents of this Bytes as text in the Appendable.
|
int |
available() |
void |
busyLockInt(long offset)
Lock which uses 4 bytes.
|
void |
busyLockLong(long offset)
Lock across processes
|
ByteOrder |
byteOrder() |
Bytes |
bytes()
Create a bytes whose content is the whole bytes store.
|
Bytes |
bytes(long offset,
long length)
|
long |
capacity() |
char |
charAt(int index) |
void |
checkEndOfBuffer() |
Bytes |
clear()
Clears this buffer.
|
void |
clearThreadAssociation()
Needed if the buffer is created in one thread and used in another.
|
void |
close()
Finishes the excerpt entry if not finished()
|
boolean |
compare(long offset,
RandomDataInput input,
long inputOffset,
long len) |
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.
|
File |
file() |
void |
finish()
Mark the end of the message if writing and check we are at the end of the message if reading.
|
Bytes |
flip()
Flips this buffer.
|
void |
flush()
Check the end of the stream has not overflowed.
|
void |
free() |
int |
getAndAdd(long offset,
int delta)
Atomically adds the given value to the current value.
|
InputStream |
inputStream() |
boolean |
isFinished() |
int |
length() |
long |
limit() |
Bytes |
limit(long limit) |
Bytes |
load()
Access every page to ensure those pages are in memory.
|
ObjectSerializer |
objectSerializer() |
OutputStream |
outputStream() |
Boolean |
parseBoolean(StopCharTester tester)
Return true or false, or null if it could not be detected
as true or false.
|
MutableDecimal |
parseDecimal(MutableDecimal decimal) |
double |
parseDouble() |
<E extends Enum<E>> |
parseEnum(Class<E> eClass,
StopCharTester tester) |
long |
parseLong() |
long |
parseLong(int base) |
String |
parseUtf8(StopCharTester tester) |
void |
parseUtf8(StringBuilder builder,
StopCharTester tester)
Populate a StringBuilder with the UTF encoded text until the end.
|
long |
position() |
Bytes |
position(long position) |
int |
read()
Reads a byte of data.
|
int |
read(byte[] byteArray)
Reads into an array of bytes.
|
int |
read(byte[] byteArray,
int off,
int len)
Reads into an array of bytes.
|
void |
read(ByteBuffer bb)
Copy bytes into a ByteBuffer to the minimum of the length
remaining() in the ByteBuffer or the
Excerpt. |
void |
read(ByteBuffer bb,
int length)
Copy bytes into a ByteBuffer to the minimum of the length in the ByteBuffer or the
Excerpt.
|
boolean |
read8bitText(StringBuilder stringBuilder) |
boolean |
readBoolean()
Reads one input byte and returns
true if that byte is nonzero, false if that byte is
zero. |
boolean |
readBoolean(long offset)
Reads one input byte and returns
true if that byte is nonzero, false if that byte is
zero. |
byte |
readByte()
Reads and returns one input byte.
|
byte |
readByte(long offset)
Reads and returns one input byte.
|
char |
readChar()
Reads two input bytes and returns a
char value. |
char |
readChar(long offset)
Reads two input bytes and returns a
char value. |
double |
readCompactDouble()
Reads the first four bytes as readFloat().
|
int |
readCompactInt()
Reads two or six input bytes and returns an
int value. |
long |
readCompactLong()
Reads four or twelve input bytes and returns a
long value. |
short |
readCompactShort()
Reads one or three input bytes and returns a
short value. |
long |
readCompactUnsignedInt()
Reads two or six input bytes and returns an
int value. |
int |
readCompactUnsignedShort()
Reads one or three input bytes and returns a
short value. |
double |
readDouble()
Reads eight input bytes and returns a
double value. |
double |
readDouble(long offset)
Reads eight input bytes and returns a
double value. |
<E> E |
readEnum(Class<E> eClass)
Read a String with
readUTFΔ which is converted to an enumerable type. |
<E> E |
readEnum(long offset,
int maxSize,
Class<E> eClass) |
float |
readFloat()
Reads four input bytes and returns a
float value. |
float |
readFloat(long offset)
Reads four input bytes and returns a
float value. |
void |
readFully(byte[] byteArray)
Reads some bytes from an input stream and stores them into the buffer array
b . |
void |
readFully(byte[] byteArray,
int off,
int len)
Reads
len bytes from an input stream. |
void |
readFully(char[] data) |
void |
readFully(char[] data,
int off,
int len) |
void |
readFully(long offset,
byte[] byteArray,
int off,
int len) |
long |
readIncompleteLong(long offset)
Same as readLong except the remaining() can be less than 8.
|
<T> T |
readInstance(Class<T> objClass,
T obj)
Read an instance of a class assuming objClass was provided when written.
|
int |
readInt()
Reads four input bytes and returns an
int value. |
int |
readInt(long offset)
Reads four input bytes and returns an
int value. |
int |
readInt24()
Reads three input bytes and returns a 24-bit
int value. |
int |
readInt24(long offset)
Reads three input bytes and returns a 24-bit
int value. |
long |
readInt48()
Reads six input bytes and returns a
long value. |
long |
readInt48(long offset)
Reads six input bytes and returns a
long value. |
String |
readLine()
Reads the next line of text from the input stream.
|
<E> void |
readList(Collection<E> list,
Class<E> eClass)
Read a stop bit encoded length and populates this Collection after zeroOut()ing it.
|
long |
readLong()
Reads eight input bytes and returns a
long value. |
long |
readLong(long offset)
Reads eight input bytes and returns a
long value. |
<K,V> Map<K,V> |
readMap(Map<K,V> map,
Class<K> kClass,
Class<V> vClass)
Read a stop bit encoded length and populates this Map after zeroOut()ing it.
|
void |
readMarshallable(Bytes in)
read an object from bytes
|
Object |
readObject()
Read and return an object.
|
<T> T |
readObject(Class<T> tClass)
Read and return an object.
|
void |
readObject(Object object,
int start,
int end)
Read the object from start to end bytes
|
short |
readShort()
Reads two input bytes and returns a
short value. |
short |
readShort(long offset)
Reads two input bytes and returns a
short value. |
long |
readStopBit()
Reads between one and ten bytes with are stop encoded with support for negative numbers
|
int |
readUnsignedByte()
Reads one input byte, zero-extends it to type
int , and returns the result, which is therefore in the
range 0 through 255 . |
int |
readUnsignedByte(long offset)
Reads one input byte, zero-extends it to type
int , and returns the result, which is therefore in the
range 0 through 255 . |
int |
readUnsignedByteOrThrow() |
long |
readUnsignedInt()
Reads four input bytes and returns an
int value. |
long |
readUnsignedInt(long offset)
Reads four input bytes and returns an
int value. |
int |
readUnsignedShort()
Reads two input bytes and returns an
int value in the range 0 through
65535 . |
int |
readUnsignedShort(long offset)
Reads two input bytes and returns an
int value in the range 0 through
65535 . |
String |
readUTF()
Reads in a string that has been encoded using a modified UTF-8 format.
|
String |
readUTFΔ()
The same as readUTF() except the length is stop bit encoded.
|
String |
readUTFΔ(long offset)
The same as readUTFΔ() except an offset is given.
|
boolean |
readUTFΔ(StringBuilder stringBuilder)
The same as readUTFΔ() except the chars are copied to a truncated StringBuilder.
|
double |
readVolatileDouble(long offset)
This is the same as readDouble() except a read barrier is performed first.
|
float |
readVolatileFloat(long offset)
This is the same as readFloat() except a read barrier is performed first.
|
int |
readVolatileInt()
This is the same as readInt() except a read barrier is performed first.
|
int |
readVolatileInt(long offset)
This is the same as readInt() except a read barrier is performed first.
|
long |
readVolatileLong()
This is the same readLong() except a dread barrier is performed first
|
long |
readVolatileLong(long offset)
This is the same readLong() except a dread barrier is performed first
|
int |
refCount() |
boolean |
release() |
long |
remaining() |
void |
reserve() |
void |
resetLockInt(long offset)
Lock which uses 4 bytes.
|
void |
resetLockLong(long offset)
Lock which uses 8 bytes.
|
boolean |
selfTerminating() |
void |
selfTerminating(boolean selfTerminate)
If set to true, the end of the Bytes will be the end of any consuming String, double or long.
|
long |
size() |
long |
skip(long n)
Skips n bytes of input.
|
int |
skipBytes(int n)
Makes an attempt to skip over
n bytes of data from the input stream, discarding the skipped bytes. |
boolean |
skipTo(StopCharTester tester)
Wind from this positionAddr to the end of the field
|
Bytes |
slice()
Creates a new bytes whose content is a shared subsequence of this bytes'
content.
|
Bytes |
slice(long offset,
long length)
Creates a new bytes whose content is a shared subsequence of this bytes'
content.
|
ByteBuffer |
sliceAsByteBuffer(ByteBuffer toReuse)
Returns a
ByteBuffer whose content is a shared subsequence of this bytes' content. |
boolean |
startsWith(RandomDataInput keyBytes) |
boolean |
stepBackAndSkipTo(StopCharTester tester)
Make sure we just read a stop character
|
CharSequence |
subSequence(int start,
int end) |
int |
threadIdForLockInt(long offset)
Lock which uses 4 bytes.
|
long |
threadIdForLockLong(long offset)
Lock which uses 8 bytes.
|
String |
toDebugString() |
String |
toDebugString(long limit) |
String |
toHexString(long limit) |
void |
toString(Appendable sb,
long start,
long position,
long end)
Write a portion of the Bytes to an Appendable for printing.
|
boolean |
tryLockInt(long offset)
Lock which uses 4 bytes.
|
boolean |
tryLockLong(long offset)
Lock across processes
|
boolean |
tryLockNanosInt(long offset,
long nanos)
Lock which uses 4 bytes.
|
boolean |
tryLockNanosLong(long offset,
long nanos)
Lock across processes
|
boolean |
tryRWReadLock(long offset,
long timeOutNS)
Uses the 64-bit long at the offset as a non-reentrant read/write lock.
|
boolean |
tryRWWriteLock(long offset,
long timeOutNS)
Uses the 64-bit long at the offset as a non-reentrant read/write lock.
|
void |
unlockInt(long offset)
Lock which uses 4 bytes.
|
void |
unlockLong(long offset)
Lock across processes
|
void |
unlockRWReadLock(long offset)
Uses the 64-bit long at the offset as a non-reentrant read/write lock.
|
void |
unlockRWWriteLock(long offset)
Uses the 64-bit long at the offset as a non-reentrant read/write lock.
|
void |
write(byte[] byteArray)
Writes to the output stream all the bytes in array
bytes . |
void |
write(byte[] byteArray,
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[] byteArray)
Writes to the output stream all the bytes in array
bytes . |
void |
write(long offset,
byte[] byteArray,
int off,
int len) |
void |
write(long offset,
Bytes bytes) |
void |
write(RandomDataInput in)
Copies the contents of a RandomDataInput from the position to the limit.
|
void |
write(RandomDataInput in,
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 |
writeMarshallable(Bytes out)
write an object to bytes
|
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
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
nextSetBit
chars, codePoints, toString
protected WrappedBytes(B wrapped)
public void clearThreadAssociation()
Bytes
clearThreadAssociation
in interface Bytes
public ByteBuffer sliceAsByteBuffer(@Nullable ByteBuffer toReuse)
BytesCommon
ByteBuffer
whose content is a shared subsequence of this bytes' content.
The content of the returned ByteBuffer
will start at this bytes' current
position. Changes to this bytes' content will be visible in the returned ByteBuffer
,
and vice versa; this bytes' and the returned ByteBuffer
's position and limit values
will be independent.
The returned ByteBuffer
's position will be zero, its capacity and its limit
will be the number of bytes remaining in this bytes.
If this bytes object is able to reuse to given toReuse
ByteBuffer
, it will
be reused and returned back from this method, otherwise a new ByteBuffer
instance
is created and returned.
sliceAsByteBuffer
in interface BytesCommon
toReuse
- a ByteBuffer
to reuseByteBuffer
view of this Bytes
BytesCommon.slice()
,
ByteBuffer.slice()
public void readMarshallable(@NotNull Bytes in) throws IllegalStateException
BytesMarshallable
readMarshallable
in interface BytesMarshallable
in
- to read fromIllegalStateException
- if the object could not be read.public String toDebugString(long limit)
toDebugString
in interface BytesCommon
public String toHexString(long limit)
toHexString
in interface BytesCommon
public boolean compare(long offset, RandomDataInput input, long inputOffset, long len)
compare
in interface RandomDataInput
public long readCompactLong()
RandomDataInput
long
value. Let a
be the first int read
with readInt(). This mapped as follows; Integer.MIN_VALUE => Long.MIN_VALUE, Integer.MAX_VALUE => Long.MAX_VALUE,
Integer.MIN_VALUE+2 to Integer.MAX_VALUE-1 => same as short value, Integer.MIN_VALUE+1 => readLong().
This method is suitable for reading the bytes written by the writeCompactLong
method of interface
RandomDataOutput
.
readCompactLong
in interface RandomDataInput
public boolean tryLockNanosInt(long offset, long nanos)
RandomDataUpdate
tryLockNanosInt
in interface RandomDataUpdate
offset
- of the start of the 4-byte locknanos
- to try to lock forpublic void writeMarshallable(@NotNull Bytes out)
BytesMarshallable
writeMarshallable
in interface BytesMarshallable
out
- to write topublic int readInt24()
RandomDataInput
int
value. Let a-c
be the first through
third bytes read on big endian machines, and the opposite on little endian machines. The value returned is:
((((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8))) >> 8
This method is suitable for reading bytes written by the writeInt24
method of interface
RandomDataOutput
.readInt24
in interface RandomDataInput
int
value read.public void flush()
RandomDataOutput
flush
in interface ObjectOutput
flush
in interface RandomDataOutput
public void writeDouble(long offset, double v)
RandomDataOutput
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 RandomDataOutput
offset
- to write tov
- the double
value to be written.public long limit()
limit
in interface BytesCommon
@NotNull public ByteStringAppender appendTimeMillis(long timeInMS)
appendTimeMillis
in interface ByteStringAppender
@Nullable public <E extends Enum<E>> E parseEnum(@NotNull Class<E> eClass, @NotNull StopCharTester tester) throws BufferUnderflowException
parseEnum
in interface ByteStringParser
BufferUnderflowException
public int refCount()
refCount
in interface ReferenceCounted
public void writeShort(long offset, int v)
RandomDataOutput
(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 RandomDataOutput
offset
- to be written tov
- the short
value to be written.public <E> void writeEnum(@Nullable E e)
RandomDataOutput
valueOf(String)
method.writeEnum
in interface RandomDataOutput
E
- element classe
- to enumerate@NotNull public <E> ByteStringAppender append(@NotNull Iterable<E> list, @NotNull CharSequence separator)
append
in interface ByteStringAppender
public void writeCompactUnsignedShort(int v)
RandomDataOutput
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
.
writeCompactUnsignedShort
in interface RandomDataOutput
v
- the unsigned short
value to be written.public long readVolatileLong()
RandomDataInput
Reads eight input bytes and returns a long
value. Let a-h
be the first through eighth
bytes read on big endian machines, and the opposite on little endian machines. The value returned is:
(((long)(a & 0xff) << 56) |
((long)(b & 0xff) << 48) |
((long)(c & 0xff) << 40) |
((long)(d & 0xff) << 32) |
((long)(e & 0xff) << 24) |
((long)(f & 0xff) << 16) |
((long)(g & 0xff) << 8) |
((long)(h & 0xff)))
This method is suitable for reading bytes written by the writeOrderedLong
or
writeVolatileLong
method of interface RandomDataOutput
.
readVolatileLong
in interface RandomDataInput
long
value read.public void write(RandomDataInput in, long position, long length)
RandomDataOutput
write
in interface RandomDataOutput
in
- to copyposition
- to copy fromlength
- to copypublic void write(Byteable byteable)
RandomDataOutput
write
in interface RandomDataOutput
byteable
- to copypublic void writeOrderedInt(int v)
RandomDataOutput
This is much faster than a volatile write which stalls the pipeline. The data is visible to other threads at the same time.
writeOrderedInt
in interface RandomDataOutput
v
- value to writepublic boolean readUTFΔ(@NotNull StringBuilder stringBuilder)
RandomDataInput
readUTFΔ
in interface RandomDataInput
stringBuilder
- to copy chars totrue
if there was a String, or false
if it was null
public void writeInt48(long offset, long v)
RandomDataOutput
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)
.
writeInt48
in interface RandomDataOutput
offset
- to be written tov
- the long
value to be written.public long readLong()
RandomDataInput
long
value. Let a-h
be the first through eighth
bytes read on big endian machines, and the opposite on little endian machines. The value returned is:
(((long)(a & 0xff) << 56) |
((long)(b & 0xff) << 48) |
((long)(c & 0xff) << 40) |
((long)(d & 0xff) << 32) |
((long)(e & 0xff) << 24) |
((long)(f & 0xff) << 16) |
((long)(g & 0xff) << 8) |
((long)(h & 0xff)))
This method is suitable for reading bytes written by the writeLong
method of interface
DataOutput
.
readLong
in interface DataInput
readLong
in interface RandomDataInput
long
value read.public long readIncompleteLong(long offset)
RandomDataInput
readIncompleteLong
in interface RandomDataInput
offset
- basepublic void writeLong(long v)
RandomDataOutput
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
writeLong
in interface RandomDataOutput
v
- the long
value to be written.@NotNull public ByteStringAppender appendDateTimeMillis(long timeInMS)
appendDateTimeMillis
in interface ByteStringAppender
@Nullable public <E> E readEnum(@NotNull Class<E> eClass)
RandomDataInput
readUTFΔ
which is converted to an enumerable type. i.e. where there is a one to
one mapping between an object and it's toString().
This is suitable to read an object written using writeEnum()
in the RandomDataOutput
interface
readEnum
in interface RandomDataInput
E
- the enum classeClass
- to decode the String asnull
with be return if null was written.public void write(RandomDataInput in)
RandomDataOutput
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());
write
in interface RandomDataOutput
in
- to copy@NotNull public ByteStringAppender append(double d)
append
in interface ByteStringAppender
@NotNull public String toDebugString()
toDebugString
in interface BytesCommon
public boolean isFinished()
isFinished
in interface BytesCommon
public void writeCompactUnsignedInt(long v)
RandomDataOutput
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
.
writeCompactUnsignedInt
in interface RandomDataOutput
v
- the short
value to be written.@NotNull public ByteStringAppender append(double d, int precision)
append
in interface ByteStringAppender
public int readUnsignedByteOrThrow() throws BufferUnderflowException
readUnsignedByteOrThrow
in interface ByteStringParser
BufferUnderflowException
- if the end is reached and selfTerminating is false.public Bytes zeroOut(long start, long end)
RandomDataOutput
zeroOut
in interface RandomDataOutput
start
- first byte to zero outend
- the first byte after the last to zero out (exclusive bound)public Bytes zeroOut(long start, long end, boolean ifNotZero)
RandomDataOutput
zeroOut
in interface RandomDataOutput
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.public void writeShort(int v)
RandomDataOutput
(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
writeShort
in interface RandomDataOutput
v
- the short
value to be written.public short addShort(long offset, short s)
addShort
in interface RandomDataUpdate
public void writeUnsignedInt(long v)
RandomDataOutput
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
.
writeUnsignedInt
in interface RandomDataOutput
v
- the int
value to be written.public void free()
free
in interface BytesStore
public int readUnsignedShort()
RandomDataInput
int
value in the range 0
through
65535
. Let a
be the first byte read and b
be the second byte on big endian
machines, and the opposite on little endian machines. The value returned is:
(((a & 0xff) << 8) | (b & 0xff))
This method is suitable for reading the bytes written by the writeUnsignedShort
method of interface
DataOutput
if the argument to writeUnsignedShort
was intended to be a value in the
range 0
through 65535
.readUnsignedShort
in interface DataInput
readUnsignedShort
in interface RandomDataInput
public void writeStopBit(long n)
RandomDataOutput
writeStopBit
in interface RandomDataOutput
n
- the number to write@Nullable public <T> T readObject(Class<T> tClass) throws IllegalStateException
RandomDataInput
readObject
in interface RandomDataInput
T
- the class of the object to readtClass
- the class of the object to readIllegalStateException
- the class of a serialized object cannot be found or any of the usual Input/Output
related exceptions occur.public void writeCompactInt(int v)
RandomDataOutput
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
.
writeCompactInt
in interface RandomDataOutput
v
- the int
value to be written.public void writeOrderedLong(long v)
RandomDataOutput
This is much faster than a volatile write which stalls the pipeline. The data is visible to other threads at the same time.
writeOrderedLong
in interface RandomDataOutput
v
- value to writepublic byte addByte(long offset, byte b)
addByte
in interface RandomDataUpdate
public int readVolatileInt()
RandomDataInput
Reads four input bytes and returns
an int
value. Let a-d
be the first through fourth bytes read on big endian machines,
and the opposite on little endian machines. The value returned is:
(((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff))
This method is suitable for reading bytes written by the writeOrderedInt
or
writeVolatileInt
method of interface RandomDataOutput
.readVolatileInt
in interface RandomDataInput
int
value read.public void close()
RandomDataInput
close
in interface ObjectInput
close
in interface ObjectOutput
close
in interface AutoCloseable
close
in interface RandomDataInput
close
in interface RandomDataOutput
public void read(@NotNull ByteBuffer bb)
RandomDataInput
remaining()
in the ByteBuffer or the
Excerpt.read
in interface RandomDataInput
bb
- to copy intopublic void read(@NotNull ByteBuffer bb, int length)
RandomDataInput
read
in interface RandomDataInput
bb
- to copy intolength
- number of bytes to copy@NotNull public ByteStringAppender append(long l, int base)
append
in interface ByteStringAppender
public long skip(long n)
RandomDataInput
skip
in interface ObjectInput
skip
in interface RandomDataInput
n
- the number of bytes to be skippedpublic boolean selfTerminating()
selfTerminating
in interface ByteStringParser
public void writeBytes(@NotNull String s)
RandomDataOutput
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
writeBytes
in interface RandomDataOutput
s
- the string of bytes to be written. Cannot be null.public long size()
size
in interface BytesStore
public int readCompactUnsignedShort()
RandomDataInput
short
value. Let a
be the first byte read.
This mapped as follows; -1 => readUnsignedShort(), default => (a & 0xFF)
This method is suitable for reading the bytes written by the writeCompactUnsignedShort
method of
interface RandomDataOutput
.
readCompactUnsignedShort
in interface RandomDataInput
@NotNull public ByteStringAppender append(@NotNull CharSequence s, int start, int end)
append
in interface Appendable
append
in interface ByteStringAppender
public void writeCompactLong(long v)
RandomDataOutput
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
.
writeCompactLong
in interface RandomDataOutput
v
- the long
value to be written.public double readCompactDouble()
RandomDataInput
readCompactDouble
in interface RandomDataInput
double
value read.public void writeOrderedInt(long offset, int v)
RandomDataOutput
This is much faster than writeVolatileInt
as the volatile write stalls the pipeline. The data is
visible to other threads at the same time.
writeOrderedInt
in interface RandomDataOutput
offset
- to write tov
- value to writepublic void writeObject(Object object, int start, int end)
RandomDataOutput
writeObject
in interface RandomDataOutput
object
- to copy fromstart
- first byte inclusiveend
- last byte exclusive.public CharSequence asString()
ByteStringParser
asString
in interface ByteStringParser
@Nullable public String readUTFΔ()
RandomDataInput
null
values are also supportedreadUTFΔ
in interface RandomDataInput
null
if writeUTFΔ(null)
was calledpublic Bytes flip()
BytesCommon
After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of channel-write or relative get operations. For example:
buf.put(magic); // Prepend header
in.read(buf); // Read data into rest of buffer
buf.flip(); // Flip buffer
out.write(buf); // Write header + data to channel
This method is often used in conjunction with the compact
method when transferring data from
one place to another.
flip
in interface BytesCommon
public int addInt(long offset, int i)
addInt
in interface RandomDataUpdate
public long readUnsignedInt(long offset)
RandomDataInput
int
value. Let a-d
be the first through fourth
bytes read on big endian machines, and the opposite on little endian machines. The value returned is:
((((long) a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d &
0xff))
This method is suitable for reading bytes written by the writeUnsignedInt
method of interface
RandomDataOutput
.readUnsignedInt
in interface RandomDataInput
offset
- to read fromint
value read.public void writeByte(int v)
RandomDataOutput
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
writeByte
in interface RandomDataOutput
v
- the byte value to be written.public void writeUnsignedInt(long offset, long v)
RandomDataOutput
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
.
writeUnsignedInt
in interface RandomDataOutput
offset
- to be written tov
- the int
value to be written.public void writeInt(int v)
RandomDataOutput
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
writeInt
in interface RandomDataOutput
v
- the int
value to be written.public short readShort()
RandomDataInput
short
value. Let a
be the first byte read and
b
be the second byte on big endian machines, and the opposite on little endian machines. The value
returned is:
(short)((a << 8) | (b & 0xff))
This method is suitable for reading the bytes written by the writeShort
method of interface
DataOutput
.readShort
in interface DataInput
readShort
in interface RandomDataInput
public void writeUnsignedByte(long offset, int v)
RandomDataOutput
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
.writeUnsignedByte
in interface RandomDataOutput
offset
- to write bytev
- the unsigned byte value to be written.public void asString(Appendable appendable)
ByteStringParser
asString
in interface ByteStringParser
appendable
- to append topublic long readInt48(long offset)
RandomDataInput
long
value. Let a-f
be the first through sixth
bytes read on big endian machines, and the opposite on little endian machines. The value returned is:
(((long)(a & 0xff) << 56) |
((long)(b & 0xff) << 48) |
((long)(c & 0xff) << 40) |
((long)(d & 0xff) << 32) |
((long)(e & 0xff) << 24) |
((long)(f & 0xff) << 16)) >> 16
This method is suitable for reading bytes written by the writeInt48
method of interface
RandomDataOutput
.
readInt48
in interface RandomDataInput
offset
- of the long to readlong
value read.public void unlockRWReadLock(long offset) throws IllegalStateException
RandomDataUpdate
unlockRWReadLock
in interface RandomDataUpdate
offset
- of the long monitorIllegalStateException
- if the monitor is in an illegal state@NotNull public String readUTF()
RandomDataInput
readUTF
is that it reads a representation of a Unicode character string encoded in
modified UTF-8 format; this string of characters is then returned as a String
.
First, two bytes are read and used to construct an unsigned 16-bit integer in exactly the manner of the
readUnsignedShort
method . This integer value is called the UTF length and specifies the
number of additional bytes to be read. These bytes are then converted to characters by considering them in
groups. The length of each group is computed from the value of the first byte of the group. The byte following a
group, if any, is the first byte of the next group.
If the first byte of a group matches the bit pattern 0xxxxxxx
(where x
means "may be
0
or 1
"), then the group consists of just that byte. The byte is zero-extended to form
a character.
If the first byte of a group matches the bit pattern 110xxxxx
, then the group consists of that byte
a
and a second byte b
. If there is no byte b
(because byte a
was the last of the bytes to be read), or if byte b
does not match the bit pattern
10xxxxxx
, then a UTFDataFormatException
is thrown. Otherwise, the group is converted to
the character:
(char)(((a& 0x1F) << 6) | (b & 0x3F))
If the first byte of a group matches the bit pattern 1110xxxx
, then the group consists of that byte
a
and two more bytes b
and c
. If there is no byte c
(because
byte a
was one of the last two of the bytes to be read), or either byte b
or byte
c
does not match the bit pattern 10xxxxxx
, then a UTFDataFormatException
is thrown. Otherwise, the group is converted to the character:
(char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F))
If the first byte of a group matches the pattern 1111xxxx
or the pattern 10xxxxxx
, then
a UTFDataFormatException
is thrown.
If end of file is encountered at any time during this entire process, then an EOFException
is
thrown.
After every group has been converted to a character by this process, the characters are gathered, in the same
order in which their corresponding groups were read from the input stream, to form a String
, which
is returned.
The writeUTF
method of interface DataOutput
may be used to write data that is suitable
for reading by this method.
readUTF
in interface DataInput
readUTF
in interface RandomDataInput
public void writeUnsignedShort(long offset, int v)
RandomDataOutput
(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
.
writeUnsignedShort
in interface RandomDataOutput
offset
- to be written tov
- the unsigned short
value to be written.public void readFully(@NotNull char[] data)
readFully
in interface RandomDataInput
public void writeInt24(long offset, int v)
RandomDataOutput
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
.
writeInt24
in interface RandomDataOutput
offset
- to be written tov
- the int
value to be written.public void writeChars(@NotNull CharSequence cs)
RandomDataOutput
CharSequence
to the bytes, without encoding.writeChars
in interface RandomDataOutput
cs
- the CharSequence
to be written. Cannot be null.RandomDataOutput.writeChars(String)
public float readFloat(long offset)
RandomDataInput
float
value. It does this by first constructing an
int
value in exactly the manner of the readInt
method, then converting this
int
value to a float
in exactly the manner of the method
Float.intBitsToFloat
. This method is suitable for reading bytes written by the
writeFloat
method of interface DataOutput
.readFloat
in interface RandomDataInput
offset
- to read fromfloat
value read.public long capacity()
capacity
in interface BytesCommon
public CharSequence subSequence(int start, int end)
subSequence
in interface CharSequence
public Bytes clear()
BytesCommon
Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example:
buf.clear(); // Prepare buffer for reading
in.read(buf); // Read data
This method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which that might as well be the case.
clear
in interface BytesCommon
@Nullable public String readUTFΔ(long offset) throws IllegalStateException
RandomDataInput
readUTFΔ
in interface RandomDataInput
offset
- to read fromnull
if writeUTFΔ(null)
was calledIllegalStateException
- if the length to be read is out of range.@NotNull public ObjectSerializer objectSerializer()
objectSerializer
in interface BytesCommon
objectSerializer
in interface BytesStore
public void writeOrderedLong(long offset, long v)
RandomDataOutput
This is much faster than a volatile write which stalls the pipeline. The data is visible to other threads at the same time.
writeOrderedLong
in interface RandomDataOutput
offset
- to be written tov
- value to writepublic long addAtomicLong(long offset, long l)
addAtomicLong
in interface RandomDataUpdate
@NotNull public ByteStringAppender append(char c)
append
in interface Appendable
append
in interface ByteStringAppender
public void busyLockInt(long offset) throws InterruptedException, IllegalStateException
RandomDataUpdate
busyLockInt
in interface RandomDataUpdate
offset
- of the start of the 4-byte lockInterruptedException
- if interruptedIllegalStateException
- if the thread tries to lock it 255 nested time (without an unlock)public void resetLockInt(long offset)
RandomDataUpdate
resetLockInt
in interface RandomDataUpdate
offset
- of the start of the 4-byte lock@Nullable public String readLine()
RandomDataInput
String
. Note that because this method processes bytes, it does not support input of the full
Unicode character set.
If end of file is encountered before even one byte can be read, then null
is returned. Otherwise,
each byte that is read is converted to type char
by zero-extension. If the character
'\n'
is encountered, it is discarded and reading ceases. If the character '\r'
is
encountered, it is discarded and, if the following byte converts to the character '\n'
, then
that is discarded also; reading then ceases. If end of file is encountered before either of the characters
'\n'
and '\r'
is encountered, reading ceases. Once reading has ceased, a
String
is returned that contains all the characters read and not discarded, taken in order. Note
that every character in this string will have a value less than \u0100
, that is,
(char)256
.
readLine
in interface DataInput
readLine
in interface RandomDataInput
null
if the end of file is encountered
before a byte can be read.public char readChar(long offset)
RandomDataInput
char
value. Let a
be the first byte read and
b
be the second byte on big endian machines, and the opposite on little endian machines. The value
returned is:
(char)((a << 8) | (b & 0xff))
This method is suitable for reading bytes written by the writeChar
method of interface
RandomDataOutput
.readChar
in interface RandomDataInput
offset
- of the char to read.char
value read.@Nullable public <T> T readInstance(@NotNull Class<T> objClass, T obj)
RandomDataInput
readInstance
in interface RandomDataInput
T
- the class of the object to readobjClass
- class to writeobj
- to reuse or null if a new object is needed@NotNull public ByteStringAppender append(boolean b)
ByteStringAppender
append
in interface ByteStringAppender
b
- to write.public int addUnsignedByte(long offset, int i)
addUnsignedByte
in interface RandomDataUpdate
public void readFully(@NotNull byte[] byteArray, int off, int len)
RandomDataInput
Reads len
bytes from an input stream.
This method blocks until one of the following conditions occurs:
len
bytes of input data are available, in which case a normal return is made.EOFException
is thrown.IOException
other than EOFException
is thrown.
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 read. Otherwise, the first byte read is stored into element bytes[off]
, the next one into
bytes[off+1]
, and so on. The number of bytes read is, at most, equal to len
.
readFully
in interface DataInput
readFully
in interface RandomDataInput
byteArray
- the buffer into which the data is read.off
- an int specifying the offset into the data.len
- an int specifying the number of bytes to read.public void readFully(@NotNull char[] data, int off, int len)
readFully
in interface RandomDataInput
public int addAndGetInt(long offset, int delta)
RandomDataOutput
addAndGetInt
in interface RandomDataOutput
offset
- of the int value to use.delta
- the value to addpublic long addUnsignedInt(long offset, long i)
addUnsignedInt
in interface RandomDataUpdate
public void writeInt48(long v)
RandomDataOutput
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)
.
writeInt48
in interface RandomDataOutput
v
- the long
value to be written.@NotNull public ByteStringAppender append(@NotNull MutableDecimal md)
append
in interface ByteStringAppender
public <K,V> Map<K,V> readMap(@NotNull Map<K,V> map, @NotNull Class<K> kClass, @NotNull Class<V> vClass)
RandomDataInput
This is suitable to reading a list written using writeMap()
in the RandomDataOutput
interface
readMap
in interface RandomDataInput
K
- the map key classV
- the map value classmap
- to populatekClass
- the map key classvClass
- the map value classpublic char charAt(int index)
charAt
in interface CharSequence
public void writeOrderedFloat(long offset, float v)
RandomDataOutput
This is much faster than a volatile write which stalls the pipeline. The data is visible to other threads at the same time.
writeOrderedFloat
in interface RandomDataOutput
offset
- to write tov
- value to writepublic void unlockRWWriteLock(long offset) throws IllegalStateException
RandomDataUpdate
unlockRWWriteLock
in interface RandomDataUpdate
offset
- of the long monitorIllegalStateException
- if the monitor is in an illegal statepublic void parseUtf8(@NotNull StringBuilder builder, @NotNull StopCharTester tester) throws BufferUnderflowException
ByteStringParser
parseUtf8
in interface ByteStringParser
builder
- to zeroOut and append to.tester
- to detect when to stop.BufferUnderflowException
@NotNull public InputStream inputStream()
inputStream
in interface BytesCommon
public long remaining()
remaining
in interface BytesCommon
public void writeByte(long offset, int b)
RandomDataOutput
b
. The 24 high-order bits of
b
are ignored.writeByte
in interface RandomDataOutput
offset
- to write byteb
- the byte to be written.public double readDouble()
RandomDataInput
double
value. It does this by first constructing a
long
value in exactly the manner of the readLong
method, then converting this
long
value to a double
in exactly the manner of the method
Double.longBitsToDouble
. This method is suitable for reading bytes written by the
writeDouble
method of interface DataOutput
.readDouble
in interface DataInput
readDouble
in interface RandomDataInput
double
value read.public int readCompactInt()
RandomDataInput
int
value. Let a
be the first short read
with readShort(). This mapped as follows; Short.MIN_VALUE => Integer.MIN_VALUE, Short.MAX_VALUE =>
Integer.MAX_VALUE, Short.MIN_VALUE+2 to Short.MAX_VALUE-1 => same as short value, Short.MIN_VALUE+1 =>
readInt().
This method is suitable for reading the bytes written by the writeCompactInt
method of interface
RandomDataOutput
.
readCompactInt
in interface RandomDataInput
public boolean release()
release
in interface ReferenceCounted
public boolean readBoolean(long offset)
RandomDataInput
true
if that byte is nonzero, false
if that byte is
zero. This method is suitable for reading the byte written by the writeBoolean
method of interface
RandomDataOutput
.readBoolean
in interface RandomDataInput
offset
- to read byte translated into a booleanboolean
value read.public void writeBoolean(boolean v)
RandomDataOutput
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
writeBoolean
in interface RandomDataOutput
v
- the boolean to be written.public int read(@NotNull byte[] byteArray)
RandomDataInput
read
in interface ObjectInput
read
in interface RandomDataInput
byteArray
- the buffer into which the data is readpublic void writeChars(@NotNull String s)
RandomDataOutput
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
writeChars
in interface RandomDataOutput
s
- the string value to be written. Cannot be null.RandomDataOutput.writeChars(CharSequence)
public Bytes slice()
BytesCommon
The content of the new bytes will start at this bytes' current position. Changes to this bytes' content will be visible in the new bytes, and vice versa; the two bytes' position and limit values will be independent.
The new bytes' position will be zero, its capacity and its limit will be the number of bytes remaining in this bytes.
slice()
is equivalent of slice(0, remaining())
.
slice
in interface BytesCommon
BytesCommon.slice(long, long)
public Bytes zeroOut()
RandomDataOutput
zeroOut
in interface RandomDataOutput
public void toString(Appendable sb, long start, long position, long end)
BytesCommon
toString
in interface BytesCommon
sb
- to append tostart
- first byteposition
- where to place a cursor or 0 = none.end
- last byte to append.public void writeOrderedDouble(long offset, double v)
RandomDataOutput
This is much faster than a volatile write which stalls the pipeline. The data is visible to other threads at the same time.
writeOrderedDouble
in interface RandomDataOutput
offset
- to write tov
- value to writepublic long readStopBit()
RandomDataInput
long l = 0, b;
int count = 0;
while ((b = readByte()) < 0) {
l |= (b & 0x7FL) << count;
count += 7;
}
if (b == 0 && count > 0)
return ~l;
return l | (b << count);
readStopBit
in interface RandomDataInput
public void busyLockLong(long offset) throws InterruptedException, IllegalStateException
RandomDataUpdate
Lock which uses 8 bytes. It store the lower 32 bits of the Thread Id, 16 bits are the process id and the re-entrant count as 16 bit. This means if you create more than 16 million threads you can get a collision, and if you try to re-enter 65535 times you will get an ISE
busyLockLong
in interface RandomDataUpdate
offset
- of the start of the 8-byte lockInterruptedException
- if interruptedIllegalStateException
- if the thread tries to lock it 65535 nested time (without an unlock)public void writeDouble(double v)
RandomDataOutput
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
writeDouble
in interface RandomDataOutput
v
- the double
value to be written.public double readDouble(long offset)
RandomDataInput
double
value. It does this by first constructing a
long
value in exactly the manner of the readLong
method, then converting this
long
value to a double
in exactly the manner of the method
Double.longBitsToDouble
. This method is suitable for reading bytes written by the
writeDouble
method of interface DataOutput
.readDouble
in interface RandomDataInput
offset
- to read fromdouble
value read.public float addFloat(long offset, float f)
addFloat
in interface RandomDataUpdate
public boolean skipTo(@NotNull StopCharTester tester)
ByteStringParser
skipTo
in interface ByteStringParser
tester
- to stop atpublic void writeChar(int v)
RandomDataOutput
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
writeChar
in interface RandomDataOutput
v
- the char
value to be written.public void writeInt(long offset, int v)
RandomDataOutput
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 RandomDataOutput
offset
- to be written tov
- the int
value to be written.@NotNull public OutputStream outputStream()
outputStream
in interface BytesCommon
public boolean compareAndSwapDouble(long offset, double expected, double x)
RandomDataOutput
x
provided the expected
value
is set already. This operation is atomic.compareAndSwapDouble
in interface RandomDataOutput
offset
- to write to.expected
- to expectx
- to set if expected was foundpublic File file()
file
in interface BytesStore
public <E> void readList(@NotNull Collection<E> list, @NotNull Class<E> eClass)
RandomDataInput
This is suitable to reading a list written using writeList()
in the RandomDataOutput
interface
readList
in interface RandomDataInput
E
- the list element classlist
- to populateeClass
- the list element classpublic void writeUnsignedByte(int v)
RandomDataOutput
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
.writeUnsignedByte
in interface RandomDataOutput
v
- the byte value to be written.public int readInt24(long offset)
RandomDataInput
int
value. Let a-c
be the first through
third bytes read on big endian machines, and the opposite on little endian machines. The value returned is:
((((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8))) >> 8
This method is suitable for reading bytes written by the writeInt24
method of interface
RandomDataOutput
.readInt24
in interface RandomDataInput
offset
- to read fromint
value read.public long readInt48()
RandomDataInput
long
value. Let a-f
be the first through sixth
bytes read on big endian machines, and the opposite on little endian machines. The value returned is:
(((long)(a & 0xff) << 56) |
((long)(b & 0xff) << 48) |
((long)(c & 0xff) << 40) |
((long)(d & 0xff) << 32) |
((long)(e & 0xff) << 24) |
((long)(f & 0xff) << 16)) >> 16
This method is suitable for reading bytes written by the writeInt48
method of interface
RandomDataOutput
.
readInt48
in interface RandomDataInput
long
value read.public void write(@NotNull char[] data)
write
in interface RandomDataOutput
@Nullable public Object readObject() throws IllegalStateException
RandomDataInput
readObject
in interface ObjectInput
readObject
in interface RandomDataInput
IllegalStateException
- the class of a serialized object cannot be found or any of the usual Input/Output
related exceptions occur.@NotNull public ByteStringAppender append(@Nullable Enum value)
append
in interface ByteStringAppender
@NotNull public String parseUtf8(@NotNull StopCharTester tester) throws BufferUnderflowException
parseUtf8
in interface ByteStringParser
BufferUnderflowException
public int readInt()
RandomDataInput
int
value. Let a-d
be the first through fourth
bytes read on big endian machines, and the opposite on little endian machines. The value returned is:
(((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff))
This method is suitable for reading bytes written by the writeInt
method of interface
DataOutput
.readInt
in interface DataInput
readInt
in interface RandomDataInput
int
value read.public void write(@NotNull char[] data, int off, int len)
write
in interface RandomDataOutput
public int addUnsignedShort(long offset, int i)
addUnsignedShort
in interface RandomDataUpdate
public float readFloat()
RandomDataInput
float
value. It does this by first constructing an
int
value in exactly the manner of the readInt
method, then converting this
int
value to a float
in exactly the manner of the method
Float.intBitsToFloat
. This method is suitable for reading bytes written by the
writeFloat
method of interface DataOutput
.readFloat
in interface DataInput
readFloat
in interface RandomDataInput
float
value read.public int available()
available
in interface ObjectInput
available
in interface RandomDataInput
public long position()
position
in interface BytesCommon
public double addDouble(long offset, double d)
addDouble
in interface RandomDataUpdate
public void write(int b)
RandomDataOutput
b
. The 24 high-order bits of
b
are ignored.write
in interface DataOutput
write
in interface ObjectOutput
write
in interface RandomDataOutput
b
- the byte to be written.public int skipBytes(int n)
RandomDataInput
n
bytes of data from the input stream, discarding the skipped bytes.
However, it may skip over some smaller number of bytes, possibly zero. This may result from any of a number of
conditions; reaching end of file before n
bytes have been skipped is only one possibility. This
method never throws an EOFException
. The actual number of bytes skipped is returned.skipBytes
in interface DataInput
skipBytes
in interface RandomDataInput
n
- the number of bytes to be skipped.public short readCompactShort()
RandomDataInput
short
value. Let a
be the first byte read.
This mapped as follows; Byte.MIN_VALUE => Short.MIN_VALUE, Byte.MAX_VALUE => Short.MAX_VALUE, Byte.MIN_VALUE+2 to
Byte.MAX_VALUE-1 => same as short value, Byte.MIN_VALUE+1 => readShort().
This method is suitable for reading the bytes written by the writeCompactShort
method of interface
RandomDataOutput
.
readCompactShort
in interface RandomDataInput
public void write(long offset, byte[] byteArray)
RandomDataOutput
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 RandomDataOutput
offset
- to be writtenbyteArray
- the data.public <E> void writeList(@NotNull Collection<E> list)
RandomDataOutput
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
writeList
in interface RandomDataOutput
E
- the class of the list elementslist
- to be writtenpublic int read(@NotNull byte[] byteArray, int off, int len)
RandomDataInput
read
in interface ObjectInput
read
in interface RandomDataInput
byteArray
- the buffer into which the data is readoff
- the start offset of the datalen
- the maximum number of bytes readpublic int readInt(long offset)
RandomDataInput
int
value. Let a-d
be the first through fourth
bytes read on big endian machines, and the opposite on little endian machines. The value returned is:
(((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff))
This method is suitable for reading bytes written by the writeInt
method of interface
RandomDataOutput
.readInt
in interface RandomDataInput
offset
- to read fromint
value read.public void writeFloat(long offset, float v)
RandomDataOutput
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 RandomDataOutput
offset
- to write tov
- the float
value to be written.public long parseLong() throws BufferUnderflowException
parseLong
in interface ByteStringParser
BufferUnderflowException
public int readUnsignedByte(long offset)
RandomDataInput
int
, and returns the result, which is therefore in the
range 0
through 255
. This method is suitable for reading the byte written by the
writeByte
method of interface RandomDataOutput
if the argument to
writeByte
was intended to be a value in the range 0
through 255
.readUnsignedByte
in interface RandomDataInput
offset
- of byte to readpublic Bytes slice(long offset, long length)
BytesCommon
The content of the new bytes will start at this bytes' current
BytesCommon.position()
+ offset
. Changes to this bytes' content
will be visible in the new bytes, and vice versa; the two bytes'
position and limit values will be independent.
The new bytes' position will be zero, its capacity and its limit
will be equal to length
.
offset
can be negative (if current bytes' position is positive)
and length
can run out of current bytes' limit, the restriction
is that new bytes' should be within this bytes' absolute bounds.
slice
in interface BytesCommon
offset
- relative offset of the new bytes from the current bytes'
positionlength
- capacity of the new bytesBytesCommon.slice()
public void writeObject(@Nullable Object object)
RandomDataOutput
writeObject
in interface ObjectOutput
writeObject
in interface RandomDataOutput
object
- to writepublic int length()
length
in interface CharSequence
public char readChar()
RandomDataInput
char
value. Let a
be the first byte read and
b
be the second byte on big endian machines, and the opposite on little endian machines. The value
returned is:
(char)((a << 8) | (b & 0xff))
This method is suitable for reading bytes written by the writeChar
method of interface
DataOutput
.readChar
in interface DataInput
readChar
in interface RandomDataInput
char
value read.public int read()
RandomDataInput
read
in interface ObjectInput
read
in interface RandomDataInput
public void writeBoolean(long offset, boolean v)
RandomDataOutput
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 RandomDataOutput
offset
- to write booleanv
- the boolean to be written.public double parseDouble() throws BufferUnderflowException
parseDouble
in interface ByteStringParser
BufferUnderflowException
public void writeCompactDouble(double v)
RandomDataOutput
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
.writeCompactDouble
in interface RandomDataOutput
v
- the double
value to be written.public float addAtomicFloat(long offset, float f)
addAtomicFloat
in interface RandomDataUpdate
public void selfTerminating(boolean selfTerminate)
ByteStringParser
selfTerminating
in interface ByteStringParser
selfTerminate
- if true, the end of the Buffer is silent.public long readCompactUnsignedInt()
RandomDataInput
int
value. Let a
be the first short read
with readShort(). This mapped as follows; -1 => readUnsignedInt(), default => (a & 0xFFFF)
This method is suitable for reading the bytes written by the writeCompactUnsignedInt
method of
interface RandomDataOutput
.
readCompactUnsignedInt
in interface RandomDataInput
public double readVolatileDouble(long offset)
RandomDataInput
Reads four input bytes and returns
a float
value.
This method is suitable for reading bytes written by the writeOrderedFloat
method of interface RandomDataOutput
.
readVolatileDouble
in interface RandomDataInput
offset
- to read fromint
value read.public long addLong(long offset, long i)
addLong
in interface RandomDataUpdate
public long readLong(long offset)
RandomDataInput
long
value. Let a-h
be the first through eighth
bytes read on big endian machines, and the opposite on little endian machines. The value returned is:
(((long)(a & 0xff) << 56) |
((long)(b & 0xff) << 48) |
((long)(c & 0xff) << 40) |
((long)(d & 0xff) << 32) |
((long)(e & 0xff) << 24) |
((long)(f & 0xff) << 16) |
((long)(g & 0xff) << 8) |
((long)(h & 0xff)))
This method is suitable for reading bytes written by the writeLong
method of interface
RandomDataOutput
.
readLong
in interface RandomDataInput
offset
- of the long to readlong
value read.public boolean compareAndSwapInt(long offset, int expected, int x)
RandomDataOutput
x
provided the expected
value
is set already. This operation is atomic.compareAndSwapInt
in interface RandomDataOutput
offset
- to write to.expected
- to expectx
- to set if expected was found@NotNull public ByteStringAppender append(@NotNull CharSequence s)
append
in interface Appendable
append
in interface ByteStringAppender
@NotNull public ByteStringAppender append(int i)
append
in interface ByteStringAppender
public <K,V> void writeMap(@NotNull Map<K,V> map)
RandomDataOutput
writeEnum
for each key and value. All the keys must be of the
same type. All values must be of the same type.writeMap
in interface RandomDataOutput
K
- the class of the map keysV
- the class of the map valuesmap
- to write outpublic Boolean parseBoolean(@NotNull StopCharTester tester) throws BufferUnderflowException
ByteStringParser
false: f, false, n, no, 0
true: t, true, y, yes, 1
parseBoolean
in interface ByteStringParser
tester
- to detect the end of the text.BufferUnderflowException
public boolean tryRWReadLock(long offset, long timeOutNS) throws IllegalStateException, InterruptedException
RandomDataUpdate
tryRWReadLock
in interface RandomDataUpdate
offset
- of the long monitortimeOutNS
- length of time to busy wait for the lock.IllegalStateException
- if the monitor is in an illegal stateInterruptedException
public int readUnsignedShort(long offset)
RandomDataInput
int
value in the range 0
through
65535
. Let a
be the first byte read and b
be the second byte on big endian
machines, and the opposite on little endian machines. The value returned is:
(((a & 0xff) << 8) | (b & 0xff))
This method is suitable for reading the bytes written by the writeShort
method of interface
RandomDataOutput
if the argument to writeUnsignedShort
was intended to be a value in
the range 0
through 65535
.readUnsignedShort
in interface RandomDataInput
offset
- of short to read.public void writeUTFΔ(long offset, int maxSize, @Nullable CharSequence s) throws IllegalStateException
RandomDataOutput
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.writeUTFΔ
in interface RandomDataOutput
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.public byte readByte(long offset)
RandomDataInput
-128
through
127
, inclusive. This method is suitable for reading the byte written by the writeByte
method of interface RandomDataOutput
.readByte
in interface RandomDataInput
offset
- of byte to read.@NotNull public ByteStringAppender append(long l)
append
in interface ByteStringAppender
public void writeUTFΔ(@Nullable CharSequence s)
RandomDataOutput
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.writeUTFΔ
in interface RandomDataOutput
s
- the string value to be written. Can be null.public boolean compareAndSwapLong(long offset, long expected, long x)
RandomDataOutput
x
provided the expected
value
is set already. This operation is atomic.compareAndSwapLong
in interface RandomDataOutput
offset
- to write to.expected
- to expectx
- to set if expected was foundpublic void writeCompactShort(int v)
RandomDataOutput
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
.
writeCompactShort
in interface RandomDataOutput
v
- the short
value to be written.public Bytes bytes()
BytesStore
bytes(0, size())
call.bytes
in interface BytesStore
BytesStore.bytes(long, long)
public void write(byte[] byteArray)
RandomDataOutput
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
write
in interface RandomDataOutput
byteArray
- the data.public void unlockInt(long offset) throws IllegalMonitorStateException
RandomDataUpdate
unlockInt
in interface RandomDataUpdate
offset
- of the start of the 4-byte lockIllegalMonitorStateException
- if this thread doesn't hold the lockpublic boolean tryLockLong(long offset)
RandomDataUpdate
Lock which uses 8 bytes. It store the lower 32 bits of the Thread Id, 16 bits are the process id and the re-entrant count as 16 bit. This means if you create more than 16 million threads you can get a collision, and if you try to re-enter 65535 times you will get an ISE
tryLockLong
in interface RandomDataUpdate
offset
- of the start of the 8-byte lockpublic byte readByte()
RandomDataInput
-128
through
127
, inclusive. This method is suitable for reading the byte written by the writeByte
method of interface DataOutput
.readByte
in interface DataInput
readByte
in interface RandomDataInput
public boolean tryRWWriteLock(long offset, long timeOutNS) throws IllegalStateException, InterruptedException
RandomDataUpdate
tryRWWriteLock
in interface RandomDataUpdate
offset
- of the long monitortimeOutNS
- length of time to busy wait for the lock.IllegalStateException
- if the monitor is in an illegal stateInterruptedException
public void write(byte[] byteArray, int off, int len)
RandomDataOutput
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
write
in interface RandomDataOutput
byteArray
- the data.off
- the start offset in the data.len
- the number of bytes to write.public void writeUTF(@NotNull String s)
RandomDataOutput
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
writeUTF
in interface RandomDataOutput
s
- the string value to be written. Cannot be nullpublic Bytes load()
BytesCommon
load
in interface BytesCommon
public int getAndAdd(long offset, int delta)
RandomDataOutput
getAndAdd
in interface RandomDataOutput
offset
- of the int value to use.delta
- the value to addpublic short readShort(long offset)
RandomDataInput
short
value. Let a
be the first byte read and
b
be the second byte on big endian machines, and the opposite on little endian machines. The value
returned is:
(short)((a << 8) | (b & 0xff))
This method is suitable for reading the bytes written by the writeShort
method of interface
RandomDataOutput
.readShort
in interface RandomDataInput
offset
- of short to read.public boolean stepBackAndSkipTo(@NotNull StopCharTester tester)
ByteStringParser
stepBackAndSkipTo
in interface ByteStringParser
tester
- to stop atpublic void resetLockLong(long offset)
RandomDataUpdate
resetLockLong
in interface RandomDataUpdate
offset
- of the start of the 8-byte lockpublic int readVolatileInt(long offset)
RandomDataInput
Reads four input bytes and returns
an int
value. Let a-d
be the first through fourth bytes read on big endian machines,
and the opposite on little endian machines. The value returned is:
(((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff))
This method is suitable for reading bytes written by the writeOrderedInt
or
writeVolatileInt
method of interface RandomDataOutput
.readVolatileInt
in interface RandomDataInput
offset
- to read fromint
value read.@NotNull public ByteOrder byteOrder()
byteOrder
in interface BytesCommon
public Bytes bytes(long offset, long length)
BytesStore
Bytes
object with start address of
address
+ offset
and capacity of length
.
If this BytesStore
is Bytes
itself rather than natural
BytesStore
object, this method will offset the new bytes from the
bytes' start, not from bytes' position like
BytesCommon.slice(long, long)
.
offset
should be non-negative, length
should be positive,
offset + length
should be less or equal to size
.
bytes
in interface BytesStore
offset
- offset of the new bytes from the bytes store addresslength
- capacity and limit of the new bytesBytes
BytesStore.bytes()
public void alignPositionAddr(int alignment)
BytesCommon
alignPositionAddr
in interface BytesCommon
alignment
- power of 2 to align to.public void writeUnsignedShort(int v)
RandomDataOutput
(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
.
writeUnsignedShort
in interface RandomDataOutput
v
- the unsigned short
value to be written.public long parseLong(int base) throws BufferUnderflowException
parseLong
in interface ByteStringParser
base
- to use.BufferUnderflowException
public boolean readBoolean()
RandomDataInput
true
if that byte is nonzero, false
if that byte is
zero. This method is suitable for reading the byte written by the writeBoolean
method of interface
DataOutput
.readBoolean
in interface DataInput
readBoolean
in interface RandomDataInput
boolean
value read.public void checkEndOfBuffer() throws IndexOutOfBoundsException
checkEndOfBuffer
in interface BytesCommon
IndexOutOfBoundsException
- if the bounds of the Bytes has been exceeded.public float readVolatileFloat(long offset)
RandomDataInput
Reads four input bytes and returns
a float
value.
This method is suitable for reading bytes written by the writeOrderedFloat
method of interface RandomDataOutput
.
readVolatileFloat
in interface RandomDataInput
offset
- to read fromint
value read.@NotNull public MutableDecimal parseDecimal(@NotNull MutableDecimal decimal) throws BufferUnderflowException
parseDecimal
in interface ByteStringParser
BufferUnderflowException
public double addAtomicDouble(long offset, double d)
addAtomicDouble
in interface RandomDataUpdate
public void unlockLong(long offset) throws IllegalMonitorStateException
RandomDataUpdate
Lock which uses 8 bytes. It store the lower 32 bits of the Thread Id, 16 bits are the process id and the re-entrant count as 16 bit. This means if you create more than 16 million threads you can get a collision, and if you try to re-enter 65535 times you will get an ISE
unlockLong
in interface RandomDataUpdate
offset
- of the start of the 8-byte lockIllegalMonitorStateException
- if this thread doesn't hold the lockpublic void writeFloat(float v)
RandomDataOutput
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
writeFloat
in interface RandomDataOutput
v
- the float
value to be written.public void reserve()
reserve
in interface ReferenceCounted
public void write(@NotNull ByteBuffer bb)
RandomDataOutput
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());
write
in interface RandomDataOutput
bb
- to copy.public long threadIdForLockLong(long offset)
RandomDataUpdate
threadIdForLockLong
in interface RandomDataUpdate
offset
- of the start of the 8-byte lockpublic void writeChar(long offset, int v)
RandomDataOutput
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 RandomDataOutput
offset
- to be written tov
- the char
value to be written.public boolean tryLockNanosLong(long offset, long nanos)
RandomDataUpdate
Lock which uses 8 bytes. It store the lower 32 bits of the Thread Id, 16 bits are the process id and the re-entrant count as 16 bit. This means if you create more than 16 million threads you can get a collision, and if you try to re-enter 65535 times you will get an ISE
tryLockNanosLong
in interface RandomDataUpdate
offset
- of the start of the 8-byte locknanos
- to try to lock forpublic int addAtomicInt(long offset, int i)
addAtomicInt
in interface RandomDataUpdate
public <OBJ> void writeInstance(@NotNull Class<OBJ> objClass, @NotNull OBJ obj)
RandomDataOutput
writeInstance
in interface RandomDataOutput
OBJ
- the class of the object to writeobjClass
- class to writeobj
- to writepublic void readFully(@NotNull byte[] byteArray)
RandomDataInput
Reads some bytes from an input stream and stores them into the buffer array b
. The number of bytes
read is equal to the length of b
.
This method blocks until one of the following conditions occurs:
b.length
bytes of input data are available, in which case a normal return is made. EOFException
is thrown.IOException
other than EOFException
is thrown.
If bytes
is null
, a NullPointerException
is thrown. If bytes.length
is zero, then no bytes are read. Otherwise, the first byte read is stored into element bytes[0]
, the
next one into bytes[1]
, and so on. If an exception is thrown from this method, then it may be that some
but not all bytes of bytes
have been updated with data from the input stream.
readFully
in interface DataInput
readFully
in interface RandomDataInput
byteArray
- the buffer into which the data is read.public Bytes position(long position)
position
in interface BytesCommon
position
- to skip topublic void writeLong(long offset, long v)
RandomDataOutput
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 RandomDataOutput
offset
- to be written tov
- the long
value to be written.public void readObject(Object object, int start, int end)
RandomDataInput
readObject
in interface RandomDataInput
object
- to read intostart
- byte inclusiveend
- byte exclusivepublic int threadIdForLockInt(long offset)
RandomDataUpdate
threadIdForLockInt
in interface RandomDataUpdate
offset
- of the start of the 4-byte lock@NotNull public ByteStringAppender appendDateMillis(long timeInMS)
appendDateMillis
in interface ByteStringAppender
public void writeInt24(int v)
RandomDataOutput
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
.
writeInt24
in interface RandomDataOutput
v
- the int
value to be written.public boolean startsWith(RandomDataInput keyBytes)
startsWith
in interface RandomDataInput
public long readUnsignedInt()
RandomDataInput
int
value. Let a-d
be the first through fourth
bytes read on big endian machines, and the opposite on little endian machines. The value returned is:
((((long) a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d &
0xff))
This method is suitable for reading bytes written by the writeUnsignedInt
method of interface
RandomDataOutput
.readUnsignedInt
in interface RandomDataInput
int
value read.public Bytes limit(long limit)
limit
in interface BytesCommon
limit
- the new limit which must be >= capacity()public void finish()
BytesCommon
finish
in interface BytesCommon
public long address()
address
in interface BytesStore
public boolean tryLockInt(long offset)
RandomDataUpdate
tryLockInt
in interface RandomDataUpdate
offset
- of the start of the 4-byte lockpublic long readVolatileLong(long offset)
RandomDataInput
Reads eight input bytes and returns a long
value. Let a-h
be the first through eighth
bytes read on big endian machines, and the opposite on little endian machines. The value returned is:
(((long)(a & 0xff) << 56) |
((long)(b & 0xff) << 48) |
((long)(c & 0xff) << 40) |
((long)(d & 0xff) << 32) |
((long)(e & 0xff) << 24) |
((long)(f & 0xff) << 16) |
((long)(g & 0xff) << 8) |
((long)(h & 0xff)))
This method is suitable for reading bytes written by the writeOrderedLong
or
writeVolatileLong
method of interface RandomDataOutput
.
readVolatileLong
in interface RandomDataInput
offset
- of the long to readlong
value read.public int readUnsignedByte()
RandomDataInput
int
, and returns the result, which is therefore in the
range 0
through 255
. This method is suitable for reading the byte written by the
writeByte
method of interface DataOutput
if the argument to writeByte
was
intended to be a value in the range 0
through 255
.readUnsignedByte
in interface DataInput
readUnsignedByte
in interface RandomDataInput
public void readFully(long offset, @NotNull byte[] byteArray, int off, int len)
readFully
in interface RandomDataInput
public void write(long offset, byte[] byteArray, int off, int len)
write
in interface RandomDataOutput
public void write(long offset, Bytes bytes)
write
in interface RandomDataOutput
public boolean read8bitText(@NotNull StringBuilder stringBuilder) throws StreamCorruptedException
read8bitText
in interface RandomDataInput
StreamCorruptedException
public <E> E readEnum(long offset, int maxSize, Class<E> eClass)
readEnum
in interface RandomDataInput
public void write8bitText(@Nullable CharSequence s)
write8bitText
in interface RandomDataOutput
public void writeEnum(long offset, int len, Object object)
writeEnum
in interface RandomDataOutput
Copyright © 2019. All rights reserved.