public class NativeBytes extends AbstractBytes
Modifier and Type | Field and Description |
---|---|
protected long |
capacityAddr |
protected long |
limitAddr |
protected static long |
NO_PAGE |
protected long |
positionAddr |
protected long |
startAddr |
static sun.misc.Unsafe |
UNSAFE
*** Access the Unsafe class *****
|
END_OF_BUFFER, finished, SLEEP_THRESHOLD, UNSIGNED_INT_MASK
Constructor and Description |
---|
NativeBytes(BytesMarshallerFactory bytesMarshallerFactory,
long startAddr,
long capacityAddr,
AtomicInteger refCount)
Deprecated.
|
NativeBytes(long startAddr,
long capacityAddr) |
NativeBytes(NativeBytes bytes) |
NativeBytes(ObjectSerializer objectSerializer,
long startAddr,
long capacityAddr,
AtomicInteger refCount) |
Modifier and Type | Method and Description |
---|---|
long |
address() |
void |
alignPositionAddr(int powerOf2)
Align the position address to a power of 2.
|
ByteOrder |
byteOrder() |
NativeBytes |
bytes()
Create a bytes whose content is the whole bytes store.
|
NativeBytes |
bytes(long offset,
long length)
|
long |
capacity() |
void |
checkEndOfBuffer() |
protected void |
cleanup() |
boolean |
compare(long offset,
RandomDataInput input,
long inputOffset,
long len) |
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.
|
static NativeBytes |
empty() |
NativeBytes |
lazyPosition(long position)
Change the position acknowleging there is no thread safety assumptions.
|
long |
limit() |
NativeBytes |
limit(long limit) |
Bytes |
load()
Access every page to ensure those pages are in memory.
|
static long |
longHash(byte[] bytes,
int off,
int len) |
long |
nextSetBit(long fromIndex)
From a given bit index, find the next bit with is set.
|
long |
position() |
NativeBytes |
position(long position) |
long |
positionAddr() |
void |
positionAddr(long positionAddr) |
int |
read(byte[] bytes,
int off,
int len)
Reads into an array of bytes.
|
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 |
readDouble()
Reads eight input bytes and returns a
double value. |
double |
readDouble(long offset)
Reads eight input bytes and returns a
double value. |
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[] b,
int off,
int len)
Reads
len bytes from an input stream. |
void |
readFully(char[] data,
int off,
int len) |
void |
readFully(long offset,
byte[] bytes,
int off,
int len) |
int |
readInt()
Reads four input bytes and returns an
int value. |
int |
readInt(long offset)
Reads four input bytes and returns an
int value. |
long |
readLong()
Reads eight input bytes and returns a
long value. |
long |
readLong(long offset)
Reads eight input bytes and returns a
long value. |
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. |
void |
readUTF0(Appendable appendable,
int utflen) |
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
|
long |
remaining() |
void |
setStartPositionAddress(long startAddr) |
void |
setStartPositionAddress(long startAddr,
long capacityAddr) |
NativeBytes |
slice()
Creates a new bytes whose content is a shared subsequence of this bytes'
content.
|
NativeBytes |
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. |
protected ByteBuffer |
sliceAsByteBuffer(ByteBuffer toReuse,
Object att) |
long |
startAddr() |
CharSequence |
subSequence(int start,
int end) |
static NativeBytes |
wrap(long address,
long capacity) |
void |
write(byte[] bytes,
int off,
int len)
Writes
len bytes from array bytes , in order, to the output stream. |
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(RandomDataInput bytes,
long position,
long length)
Copy from one Bytes to another, moves the position of "this" RandomDataOutput by the length.
|
void |
writeByte(long offset,
int b)
Writes to the output stream the eight low-order bits of the argument
b . |
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 |
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. |
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. |
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 |
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. |
void |
writeObject(Object object,
int start,
int end)
Copy data from an Object from bytes start to end.
|
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.
|
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
|
addAndGetInt, addAtomicDouble, addAtomicFloat, addAtomicInt, addAtomicLong, addByte, addDouble, addFloat, addInt, addLong, addShort, addUnsignedByte, addUnsignedInt, addUnsignedShort, append, append, append, append, append, append, append, append, append, append, append, append, appendDateMillis, appendDateTimeMillis, appendTimeMillis, asString, asString, available, busyLockInt, busyLockLong, charAt, clear, clearThreadAssociation, close, compareAndSwapDouble, compareRest, file, findUTFLength, findUTFLength, findUTFLength, finish, flip, flush, free, getAndAdd, inputStream, isFinished, length, objectSerializer, outputStream, parseBoolean, parseDecimal, parseDouble, parseEnum, parseLong, parseLong, parseUtf8, parseUtf8, read, read, read, read, read8bitText, readBoolean, readBoolean, readByteOrThrow, readCompactDouble, readCompactInt, readCompactLong, readCompactShort, readCompactUnsignedInt, readCompactUnsignedShort, readEnum, readEnum, readFully, readFully, readIncompleteLong, readInstance, readInt24, readInt24, readInt48, readInt48, readLine, readList, readMap, readMarshallable, readObject, readObject, readStopBit, readUnsignedByte, readUnsignedByte, readUnsignedByteOrThrow, readUnsignedInt, readUnsignedInt, readUnsignedShort, readUnsignedShort, readUTF, readUTF2, readUTF2, readUTFΔ, readUTFΔ, readUTFΔ, readVolatileDouble, readVolatileFloat, refCount, release, reserve, resetLockInt, resetLockLong, selfTerminating, selfTerminating, setObjectSerializer, size, skip, skipBytes, skipTo, startsWith, stepBackAndSkipTo, threadIdForLockInt, threadIdForLockLong, toDebugString, toDebugString, toHex, toHexString, toHexString, toString, toString, toString, tryLockInt, tryLockLong, tryLockNanosInt, tryLockNanosLong, tryRWReadLock, tryRWWriteLock, unlockInt, unlockLong, unlockRWReadLock, unlockRWWriteLock, write, write, write, write, write, write, write, write8bitText, writeBoolean, writeBoolean, writeByte, writeBytes, writeChars, writeChars, writeCompactDouble, writeCompactInt, writeCompactLong, writeCompactShort, writeCompactUnsignedInt, writeCompactUnsignedShort, writeEnum, writeEnum, writeInstance, writeInt24, writeInt24, writeInt48, writeInt48, writeList, writeMap, writeMarshallable, writeObject, writeOrderedDouble, writeOrderedFloat, writeStopBit, writeUnsignedByte, writeUnsignedByte, writeUnsignedInt, writeUnsignedInt, writeUnsignedShort, writeUnsignedShort, writeUTF, writeUTF0, writeUTF1, writeUTFΔ, writeUTFΔ
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
chars, codePoints
@NotNull public static final sun.misc.Unsafe UNSAFE
protected static final long NO_PAGE
protected long startAddr
protected long positionAddr
protected long limitAddr
protected long capacityAddr
public NativeBytes(long startAddr, long capacityAddr)
@Deprecated public NativeBytes(BytesMarshallerFactory bytesMarshallerFactory, long startAddr, long capacityAddr, AtomicInteger refCount)
NativeBytes(ObjectSerializer, long, long, AtomicInteger)
insteadpublic NativeBytes(ObjectSerializer objectSerializer, long startAddr, long capacityAddr, AtomicInteger refCount)
public NativeBytes(NativeBytes bytes)
public static NativeBytes empty()
public static NativeBytes wrap(long address, long capacity)
public static long longHash(byte[] bytes, int off, int len)
public void setStartPositionAddress(long startAddr, long capacityAddr)
public void setStartPositionAddress(long startAddr)
public void readUTF0(@NotNull Appendable appendable, int utflen) throws IOException
readUTF0
in class AbstractBytes
IOException
public NativeBytes 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())
.
BytesCommon.slice(long, long)
public NativeBytes 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.
offset
- relative offset of the new bytes from the current bytes'
positionlength
- capacity of the new bytesBytesCommon.slice()
public CharSequence subSequence(int start, int end)
public NativeBytes bytes()
BytesStore
bytes(0, size())
call.BytesStore.bytes(long, long)
public NativeBytes 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
.
offset
- offset of the new bytes from the bytes store addresslength
- capacity and limit of the new bytesBytes
BytesStore.bytes()
public long address()
public Bytes zeroOut()
RandomDataOutput
public Bytes zeroOut(long start, long end)
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
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 int read(@NotNull byte[] bytes, int off, int len)
RandomDataInput
read
in interface ObjectInput
read
in interface RandomDataInput
read
in class AbstractBytes
bytes
- the buffer into which the data is readoff
- the start offset of the datalen
- the maximum number of bytes readpublic byte readByte()
RandomDataInput
-128
through
127
, inclusive. This method is suitable for reading the byte written by the writeByte
method of interface DataOutput
.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
.offset
- of byte to read.public void readFully(@NotNull byte[] b, 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
.
b
- 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(long offset, byte[] bytes, int off, int len)
public void readFully(@NotNull char[] data, int off, int len)
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
.public 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
.offset
- of short to read.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
.char
value 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
.offset
- of the char to read.char
value read.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
.int
value read.public 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
.offset
- to read fromint
value read.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
.int
value read.public 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
.offset
- to read fromint
value read.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
.
long
value read.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
.
offset
- of the long to readlong
value read.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
.
long
value read.public 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
.
offset
- of the long to readlong
value read.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
.float
value read.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
.offset
- to read fromfloat
value read.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
.double
value read.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
.offset
- to read fromdouble
value read.public void write(int b)
RandomDataOutput
b
. The 24 high-order bits of
b
are ignored.b
- the byte to be written.public void writeByte(long offset, int b)
RandomDataOutput
b
. The 24 high-order bits of
b
are ignored.offset
- to write byteb
- the byte to be written.public void write(long offset, @NotNull byte[] bytes)
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
write
in class AbstractBytes
offset
- to be writtenbytes
- the data.public void write(byte[] bytes, 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
write
in class AbstractBytes
bytes
- the data.off
- the start offset in the data.len
- the number of bytes to write.public void write(long offset, byte[] bytes, int off, int len)
write
in interface RandomDataOutput
write
in class AbstractBytes
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
.
v
- the short
value to be written.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
.
offset
- to be written tov
- the short
value to be written.public 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
.
v
- the char
value to be written.public 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
.
offset
- to be written tov
- the char
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
.
v
- the int
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
.
offset
- to be written tov
- the int
value to be written.public 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.
v
- value to writepublic 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.
offset
- to write tov
- value to writepublic boolean compareAndSwapInt(long offset, int expected, int x)
RandomDataOutput
x
provided the expected
value
is set already. This operation is atomic.offset
- to write to.expected
- to expectx
- to set if expected was foundpublic 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
.
v
- the long
value to be written.public 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
.
offset
- to be written tov
- the long
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.
v
- value to writepublic 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.
offset
- to be written tov
- value to writepublic boolean compareAndSwapLong(long offset, long expected, long x)
RandomDataOutput
x
provided the expected
value
is set already. This operation is atomic.offset
- to write to.expected
- to expectx
- to set if expected was foundpublic 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
.v
- the float
value to be written.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
.offset
- to write tov
- the float
value to be written.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
.v
- the double
value to be written.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
.offset
- to write tov
- the double
value to be written.public void readObject(Object object, int start, int end)
RandomDataInput
object
- to read intostart
- byte inclusiveend
- byte exclusivepublic void writeObject(Object object, int start, int end)
RandomDataOutput
object
- to copy fromstart
- first byte inclusiveend
- last byte exclusive.public boolean compare(long offset, RandomDataInput input, long inputOffset, long len)
compare
in interface RandomDataInput
compare
in class AbstractBytes
public long position()
public NativeBytes position(long position)
position
- to skip topublic NativeBytes lazyPosition(long position)
position
- to set if we can.public void write(RandomDataInput bytes, long position, long length)
RandomDataOutput
write
in interface RandomDataOutput
write
in class AbstractBytes
bytes
- to copyposition
- to copy fromlength
- to copypublic long capacity()
public long remaining()
public long limit()
public NativeBytes limit(long limit)
limit
- the new limit which must be >= capacity()@NotNull public ByteOrder byteOrder()
public void checkEndOfBuffer() throws IndexOutOfBoundsException
IndexOutOfBoundsException
- if the bounds of the Bytes has been exceeded.public long startAddr()
protected void cleanup()
cleanup
in class AbstractBytes
public Bytes load()
BytesCommon
public void alignPositionAddr(int powerOf2)
BytesCommon
powerOf2
- power of 2 to align to.public void positionAddr(long positionAddr)
public long positionAddr()
public ByteBuffer sliceAsByteBuffer(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
sliceAsByteBuffer
in class AbstractBytes
toReuse
- a ByteBuffer
to reuseByteBuffer
view of this Bytes
BytesCommon.slice()
,
ByteBuffer.slice()
protected ByteBuffer sliceAsByteBuffer(ByteBuffer toReuse, Object att)
public long nextSetBit(long fromIndex)
RandomDataInput
nextSetBit
in interface RandomDataInput
nextSetBit
in class AbstractBytes
fromIndex
- first bit to scan.Copyright © 2019. All rights reserved.