public class NativeBytesStore<U> extends AbstractBytesStore<NativeBytesStore<U>,U>
Modifier and Type | Field and Description |
---|---|
long |
address |
protected long |
limit |
long |
maximumLimit |
net.openhft.chronicle.core.Memory |
memory |
referenceCounted, WARN_COUNT, WARN_NS
charToString
Modifier | Constructor and Description |
---|---|
|
NativeBytesStore(@NotNull ByteBuffer bb,
boolean elastic,
int maximumLimit) |
|
NativeBytesStore(long address,
long limit) |
|
NativeBytesStore(long address,
long limit,
@Nullable Runnable deallocator,
boolean elastic) |
protected |
NativeBytesStore(long address,
long limit,
@Nullable Runnable deallocator,
boolean elastic,
boolean monitored) |
Modifier and Type | Method and Description |
---|---|
int |
addAndGetInt(long offset,
int adding)
Perform an atomic add and get operation for a 32-bit int
|
long |
addAndGetLong(long offset,
long adding)
Perform an atomic add and get operation for a 64-bit long
|
long |
addressForRead(long offset)
Obtain the underlying addressForRead.
|
default long |
addressForRead(long offset,
int buffer) |
long |
addressForWrite(long offset)
Obtain the underlying addressForRead.
|
long |
addressForWritePosition() |
long |
appendUtf8(long pos,
char[] chars,
int offset,
int length) |
protected void |
backgroundPerformRelease() |
int |
byteCheckSum()
Returns the bytes sum of the readable bytes in this BytesStore.
|
int |
byteCheckSum(long position,
long limit)
Returns the bytes sum between the specified indexes; start (inclusive) and end (exclusive).
|
default ByteOrder |
byteOrder() |
@NotNull VanillaBytes<U> |
bytesForWrite()
Returns a Bytes that wraps this ByteStore from the
start to the realCapacity . |
boolean |
canReadDirect(long length) |
long |
capacity() |
boolean |
compareAndSwapInt(long offset,
int expected,
int value)
Perform a 32-bit CAS at a given offset.
|
boolean |
compareAndSwapLong(long offset,
long expected,
long value)
Perform a 64-bit CAS at a given offset.
|
@NotNull BytesStore<NativeBytesStore<U>,U> |
copy() |
long |
copyTo(@NotNull BytesStore store)
Returns the number of bytes that were copied from this BytesStore to a destination BytesStore.
|
long |
copyToDirect(@NotNull BytesStore store) |
static @NotNull NativeBytesStore<ByteBuffer> |
elasticByteBuffer() |
static @NotNull NativeBytesStore<ByteBuffer> |
elasticByteBuffer(int size,
long maxSize) |
boolean |
equals(Object obj) |
int |
fastHash(long offset,
int length) |
static @NotNull NativeBytesStore |
from(byte[] bytes) |
static @NotNull NativeBytesStore |
from(@NotNull String text)
Returns a BytesStore using the bytes in a String.
|
int |
hashCode() |
void |
init(@NotNull ByteBuffer bb,
boolean elastic) |
boolean |
isDirectMemory() |
boolean |
isEqual(long start,
long length,
String s)
Returns if a specified portion of this BytesStore is equal to a specified String.
|
static @NotNull NativeBytesStore<Void> |
lazyNativeBytesStoreWithFixedCapacity(long capacity) |
default long |
lengthWritten(long startPosition)
Typically this calculates the difference however for HexDumpBytes it's not as simple.
|
void |
move(long from,
long to,
long length) |
void |
nativeRead(long position,
long address,
long size)
expert level method for copying data to native memory.
|
static @NotNull NativeBytesStore<Void> |
nativeStore(long capacity)
this is an elastic native store
|
static @NotNull NativeBytesStore<Void> |
nativeStoreWithFixedCapacity(long capacity) |
void |
nativeWrite(long address,
long position,
long size)
expert level method to copy data from native memory into the BytesStore
|
int |
peekUnsignedByte(long offset)
Read an unsigned byte at an offset, or -1
|
protected void |
performRelease() |
long |
read(long offsetInRDI,
byte[] bytes,
int offset,
int length) |
void |
read8bit(long position,
char[] chars,
int length) |
byte |
readByte(long offset)
Read byte at an offset
|
double |
readDouble(long offset)
Read a double at an offset
|
float |
readFloat(long offset)
Read a float at an offset
|
long |
readIncompleteLong(long offset)
Read a long which is zero padded (high bytes) if the available bytes is less than 8.
|
int |
readInt(long offset)
Read an int at an offset
|
default long |
readLimit()
If the resource is closed, the returned value is unspecified.
|
long |
readLong(long offset)
Read a long at an offset
|
short |
readShort(long offset)
Read a short at an offset
|
int |
readUnsignedByte(long offset)
Read an unsigned byte at an offset
|
byte |
readVolatileByte(long offset)
Read a 8-bit byte from memory with a load barrier.
|
int |
readVolatileInt(long offset)
Read a 32-bit int from memory with a load barrier.
|
long |
readVolatileLong(long offset)
Read a 64-bit long from memory with a load barrier.
|
short |
readVolatileShort(long offset)
Read a 16-bit short from memory with a load barrier.
|
long |
realCapacity()
Returns the actual capacity that can be potentially read.
|
default long |
realReadRemaining()
If the resource is closed, the returned value is unspecified.
|
default long |
realWriteRemaining()
If the resource is closed, the returned value is unspecified.
|
long |
safeLimit() |
void |
setAddress(long address) |
boolean |
sharedMemory() |
void |
testAndSetInt(long offset,
int expected,
int value) |
@NotNull String |
toString() |
@NotNull ByteBuffer |
toTemporaryDirectByteBuffer() |
long |
translate(long offset) |
U |
underlyingObject() |
void |
uninit() |
static <T> @NotNull NativeBytesStore<T> |
uninitialized() |
static @NotNull NativeBytesStore<ByteBuffer> |
wrap(@NotNull ByteBuffer bb)
Wraps a ByteBuffer which can be either on heap or off heap.
|
@NotNull NativeBytesStore<U> |
write(long offsetInRDO,
byte[] byteArray,
int offset,
int length)
Copies the provided
byteArray to this Bytes object starting at writeOffset taking
content starting at readOffset but copying at most length bytes. |
void |
write(long offsetInRDO,
@NotNull ByteBuffer bytes,
int offset,
int length)
Copy from ByteBuffer into this.
|
@NotNull NativeBytesStore<U> |
write(long writeOffset,
@NotNull RandomDataInput bytes,
long readOffset,
long length)
Copy from RandomDataInput into this.
|
void |
write0(long offsetInRDO,
@NotNull RandomDataInput bytes,
long offset,
long length) |
long |
write8bit(long position,
@NotNull BytesStore bs)
Write the stop bit length and copy the BytesStore
|
long |
write8bit(long position,
@NotNull String s,
int start,
int length) |
@NotNull NativeBytesStore<U> |
writeByte(long offset,
byte i8)
Write an unsigned byte at an offset.
|
@NotNull NativeBytesStore<U> |
writeDouble(long offset,
double d)
Write a double at an offset.
|
@NotNull NativeBytesStore<U> |
writeFloat(long offset,
float f)
Write a float at an offset.
|
@NotNull NativeBytesStore<U> |
writeInt(long offset,
int i32)
Write an int at an offset.
|
default long |
writeLimit()
Returns the write limit.
|
@NotNull NativeBytesStore<U> |
writeLong(long offset,
long i64)
Write a long at an offset.
|
@NotNull NativeBytesStore<U> |
writeOrderedInt(long offset,
int i)
Perform a non stalling write with a store barrier.
|
@NotNull NativeBytesStore<U> |
writeOrderedLong(long offset,
long i)
Perform a non stalling write with a store barrier.
|
default long |
writePosition()
Returns the write position.
|
@NotNull NativeBytesStore<U> |
writeShort(long offset,
short i16)
Write a short at an offset.
|
@NotNull NativeBytesStore<U> |
writeVolatileByte(long offset,
byte i8) |
@NotNull NativeBytesStore<U> |
writeVolatileInt(long offset,
int i32) |
@NotNull NativeBytesStore<U> |
writeVolatileLong(long offset,
long i64) |
@NotNull NativeBytesStore<U> |
writeVolatileShort(long offset,
short i16) |
@NotNull NativeBytesStore<U> |
zeroOut(long start,
long end)
Fills the BytesStore with zeros.
|
canReleaseInBackground, readPosition, readRemaining, start, writeRemaining
addReferenceChangeListener, assertReferencesReleased, clearUsedByThread, createdHere, disableReferenceTracing, enableReferenceTracing, refCount, referenceId, release, releaseLast, removeReferenceChangeListener, reserve, reservedBy, reserveTransfer, singleThreadedCheckDisabled, singleThreadedCheckReset, threadSafetyCheck, throwExceptionIfNotReleased, throwExceptionIfReleased, tryReserve, unmonitor, warnAndReleaseIfNotReleased
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAndGetDouble, addAndGetDoubleNotAtomic, addAndGetFloat, addAndGetFloatNotAtomic, addAndGetIntNotAtomic, addAndGetShortNotAtomic, addAndGetUnsignedByteNotAtomic, bytesForRead, bytesStore, charAt, cipher, cipher, compareAndSwapDouble, compareAndSwapFloat, contentEquals, copyTo, empty, endsWith, equalBytes, forFields, from, from, hash, inside, inside, isClear, isEmpty, isImmutableEmptyByteStore, length, nativePointer, nativeStoreFrom, readWrite, startsWith, startsWith, subSequence, to8bitString, toDebugString, toDebugString, wrap, wrap, writeMaxInt, writeMaxLong
canReadDirect, compareUtf8, copyTo, copyTo, createCharToString, findByte, parseLong, peekVolatileInt, printable, readBoolean, readUnsignedInt, readUnsignedInt24, readUnsignedShort, readUtf8, readUtf8Limited, readUtf8Limited, readVolatileDouble, readVolatileFloat, subBytes, toByteArray
append, append, write, write, writeBoolean, writeByte, writeInt24, writeOrderedDouble, writeOrderedFloat, writeUnsignedByte, writeUnsignedInt, writeUnsignedShort, writeUtf8, writeUtf8Limited, writeVolatileDouble, writeVolatileFloat
addReferenceChangeListener, refCount, release, releaseLast, releaseLast, removeReferenceChangeListener, reserve, reservedBy, reserveTransfer, tryReserve
referenceId, referenceName, temporary
chars, codePoints
public long address
public net.openhft.chronicle.core.Memory memory
public long maximumLimit
protected long limit
public NativeBytesStore(@NotNull @NotNull ByteBuffer bb, boolean elastic, int maximumLimit)
public NativeBytesStore(long address, long limit)
public NativeBytesStore(long address, long limit, @Nullable @Nullable Runnable deallocator, boolean elastic)
protected NativeBytesStore(long address, long limit, @Nullable @Nullable Runnable deallocator, boolean elastic, boolean monitored)
@NotNull public static @NotNull NativeBytesStore<ByteBuffer> wrap(@NotNull @NotNull ByteBuffer bb)
BytesStore
When resulting BytesStore instance is closed, direct byteBuffer
will be deallocated and should
no longer be used.
bb
- ByteBuffer@NotNull public static <T> @NotNull NativeBytesStore<T> uninitialized()
@NotNull public static @NotNull NativeBytesStore<Void> nativeStore(long capacity) throws IllegalArgumentException
capacity
- of the buffer.IllegalArgumentException
@NotNull public static @NotNull NativeBytesStore<Void> nativeStoreWithFixedCapacity(long capacity) throws IllegalArgumentException
IllegalArgumentException
@NotNull public static @NotNull NativeBytesStore<Void> lazyNativeBytesStoreWithFixedCapacity(long capacity) throws IllegalArgumentException
IllegalArgumentException
@NotNull public static @NotNull NativeBytesStore<ByteBuffer> elasticByteBuffer()
@NotNull public static @NotNull NativeBytesStore<ByteBuffer> elasticByteBuffer(int size, long maxSize)
@NotNull public static @NotNull NativeBytesStore from(@NotNull @NotNull String text)
BytesStore
text
- a String@NotNull public static @NotNull NativeBytesStore from(byte[] bytes)
public boolean isDirectMemory()
public boolean canReadDirect(long length)
public void init(@NotNull @NotNull ByteBuffer bb, boolean elastic)
public void uninit()
public void move(long from, long to, long length) throws BufferUnderflowException, IllegalStateException
@NotNull public @NotNull BytesStore<NativeBytesStore<U>,U> copy() throws IllegalStateException
IllegalStateException
@NotNull public @NotNull VanillaBytes<U> bytesForWrite() throws IllegalStateException
BytesStore
start
to the realCapacity
.
The returned Bytes is not elastic and can be both read and written using cursors.
IllegalStateException
- if this BytesStore has been releasedpublic long realCapacity()
RandomDataInput
public long capacity()
@Nullable public U underlyingObject()
@NotNull public @NotNull NativeBytesStore<U> zeroOut(long start, long end)
BytesStore
start
- first byte inclusiveend
- last byte exclusivepublic boolean compareAndSwapInt(long offset, int expected, int value) throws IllegalStateException
RandomDataInput
offset
- to perform CASexpected
- valuevalue
- to setIllegalStateException
public void testAndSetInt(long offset, int expected, int value) throws IllegalStateException
IllegalStateException
public boolean compareAndSwapLong(long offset, long expected, long value) throws IllegalStateException
RandomDataInput
offset
- to perform CASexpected
- valuevalue
- to setIllegalStateException
public long addAndGetLong(long offset, long adding) throws BufferUnderflowException
RandomDataInput
offset
- to add and getadding
- value to add, can be 1BufferUnderflowException
- if the offset is outside the limits of the Bytespublic int addAndGetInt(long offset, int adding) throws BufferUnderflowException
RandomDataInput
offset
- to add and getadding
- value to add, can be 1BufferUnderflowException
- if the offset is outside the limits of the Bytespublic long translate(long offset)
public byte readByte(long offset)
RandomDataInput
offset
- to readpublic int readUnsignedByte(long offset) throws BufferUnderflowException
RandomDataInput
offset
- to readBufferUnderflowException
- if the offset is outside the limits of the Bytespublic short readShort(long offset)
RandomDataInput
offset
- to readpublic int readInt(long offset)
RandomDataInput
offset
- to readpublic long readLong(long offset)
RandomDataInput
offset
- to readpublic float readFloat(long offset)
RandomDataInput
offset
- to readpublic double readDouble(long offset)
RandomDataInput
offset
- to readpublic byte readVolatileByte(long offset)
RandomDataInput
offset
- to readpublic short readVolatileShort(long offset)
RandomDataInput
offset
- to readpublic int readVolatileInt(long offset)
RandomDataInput
offset
- to readpublic long readVolatileLong(long offset)
RandomDataInput
offset
- to read@NotNull public @NotNull NativeBytesStore<U> writeByte(long offset, byte i8) throws IllegalStateException
RandomDataOutput
offset
- to write toi8
- the valueIllegalStateException
@NotNull public @NotNull NativeBytesStore<U> writeShort(long offset, short i16) throws IllegalStateException
RandomDataOutput
offset
- to write toi16
- the valueIllegalStateException
@NotNull public @NotNull NativeBytesStore<U> writeInt(long offset, int i32) throws IllegalStateException
RandomDataOutput
offset
- to write toi32
- the valueIllegalStateException
@NotNull public @NotNull NativeBytesStore<U> writeOrderedInt(long offset, int i) throws IllegalStateException
RandomDataOutput
offset
- to write toi
- value to writeIllegalStateException
@NotNull public @NotNull NativeBytesStore<U> writeLong(long offset, long i64) throws IllegalStateException
RandomDataOutput
offset
- to write toi64
- the valueIllegalStateException
@NotNull public @NotNull NativeBytesStore<U> writeOrderedLong(long offset, long i) throws IllegalStateException
RandomDataOutput
offset
- to write toi
- value to writeIllegalStateException
@NotNull public @NotNull NativeBytesStore<U> writeFloat(long offset, float f) throws IllegalStateException
RandomDataOutput
offset
- to write tof
- the valueIllegalStateException
@NotNull public @NotNull NativeBytesStore<U> writeDouble(long offset, double d) throws IllegalStateException
RandomDataOutput
offset
- to write tod
- the valueIllegalStateException
@NotNull public @NotNull NativeBytesStore<U> writeVolatileByte(long offset, byte i8) throws IllegalStateException
IllegalStateException
@NotNull public @NotNull NativeBytesStore<U> writeVolatileShort(long offset, short i16) throws IllegalStateException
IllegalStateException
@NotNull public @NotNull NativeBytesStore<U> writeVolatileInt(long offset, int i32) throws IllegalStateException
IllegalStateException
@NotNull public @NotNull NativeBytesStore<U> writeVolatileLong(long offset, long i64) throws IllegalStateException
IllegalStateException
@NotNull public @NotNull NativeBytesStore<U> write(long offsetInRDO, byte[] byteArray, int offset, int length) throws IllegalStateException
RandomDataOutput
byteArray
to this Bytes object starting at writeOffset
taking
content starting at readOffset
but copying at most length
bytes.
Does not update cursors e.g. writePosition()
offsetInRDO
- non-negative offset to write tobyteArray
- non-null copy from byteArrayoffset
- non-negative copy from offsetlength
- non-negative length to copyIllegalStateException
- if this Bytes object has been previously releasedpublic void write(long offsetInRDO, @NotNull @NotNull ByteBuffer bytes, int offset, int length) throws IllegalStateException
RandomDataOutput
Does not update cursors e.g. writePosition()
offsetInRDO
- offset to write tobytes
- copy from bytesoffset
- copy from offsetIllegalStateException
@NotNull public @NotNull NativeBytesStore<U> write(long writeOffset, @NotNull @NotNull RandomDataInput bytes, long readOffset, long length) throws BufferOverflowException, BufferUnderflowException, IllegalStateException
RandomDataOutput
writePosition()
nor RandomCommon.readPosition()
writeOffset
- offset to write tobytes
- copy from bytesreadOffset
- copy from offsetBufferOverflowException
IllegalStateException
BufferUnderflowException
public void write0(long offsetInRDO, @NotNull @NotNull RandomDataInput bytes, long offset, long length) throws BufferUnderflowException, IllegalStateException
public long addressForRead(long offset) throws BufferUnderflowException
offset
- within this buffer. addressForRead(start()) is the actual addressForRead of the first byte.BufferUnderflowException
- if the offset is before the start() or the after the capacity()public long addressForWrite(long offset) throws BufferOverflowException
offset
- within this buffer. addressForRead(start()) is the actual addressForRead of the first byte.BufferOverflowException
- if the offset is before the start() or the after the capacity()public long addressForWritePosition() throws UnsupportedOperationException, BufferOverflowException
protected void backgroundPerformRelease()
backgroundPerformRelease
in class net.openhft.chronicle.core.io.AbstractReferenceCounted
protected void performRelease()
performRelease
in class net.openhft.chronicle.core.io.AbstractReferenceCounted
@NotNull public @NotNull String toString()
toString
in interface CharSequence
toString
in class net.openhft.chronicle.core.io.AbstractReferenceCounted
public void nativeRead(long position, long address, long size) throws BufferUnderflowException, IllegalStateException
RandomDataInput
position
- within the ByteStore to copy.address
- in native memorysize
- in bytesBufferUnderflowException
- if the offset is outside the limits of the BytesIllegalStateException
- if releasedpublic void nativeWrite(long address, long position, long size) throws BufferOverflowException, IllegalStateException
RandomDataOutput
address
- in native memory to copy fromposition
- in BytesStore to copy tosize
- in bytesBufferOverflowException
IllegalStateException
public long write8bit(long position, @NotNull @NotNull BytesStore bs)
RandomDataOutput
position
- to writebs
- to copy.RandomDataOutput
public long write8bit(long position, @NotNull @NotNull String s, int start, int length)
public void read8bit(long position, char[] chars, int length)
public long readIncompleteLong(long offset)
RandomDataInput
offset
- to read frompublic void setAddress(long address)
public long appendUtf8(long pos, char[] chars, int offset, int length) throws BufferOverflowException, IllegalStateException
public long copyTo(@NotNull @NotNull BytesStore store) throws IllegalStateException
BytesStore
Copies the data to another BytesStore as long as space is available in the destination BytesStore.
store
- the BytesStore to copy toIllegalStateException
- if this BytesStore has been releasedpublic long copyToDirect(@NotNull @NotNull BytesStore store) throws IllegalStateException
IllegalStateException
@NotNull public @NotNull ByteBuffer toTemporaryDirectByteBuffer()
public int byteCheckSum() throws net.openhft.chronicle.core.io.IORuntimeException
BytesStore
net.openhft.chronicle.core.io.IORuntimeException
public int byteCheckSum(long position, long limit)
BytesStore
position
- the index of the first byte to sumlimit
- the index of the last byte to sumpublic boolean sharedMemory()
public long read(long offsetInRDI, byte[] bytes, int offset, int length)
public int peekUnsignedByte(long offset)
RandomDataInput
peekUnsignedByte
in interface RandomDataInput
peekUnsignedByte
in class AbstractBytesStore<NativeBytesStore<U>,U>
offset
- to readpublic int fastHash(long offset, int length) throws BufferUnderflowException, IllegalStateException
public long safeLimit()
public boolean isEqual(long start, long length, String s)
BytesStore
start
- the portion offsetlength
- the number of bytes from this BytesStore that should be compared to ss
- the String to compare totrue
if the specified portion of this BytesStore is equal to spublic int hashCode()
hashCode
in class AbstractBytesStore<NativeBytesStore<U>,U>
public boolean equals(Object obj)
equals
in class AbstractBytesStore<NativeBytesStore<U>,U>
public long writePosition()
The write position is readPosition() <= writePosition() && writePosition() <= writeLimit()
If the resource is closed, the returned value is unspecified.
public long lengthWritten(long startPosition)
If the resource is closed, the returned value is unspecified.
startPosition
- to compare againstpublic long realReadRemaining()
If the resource is closed, the returned value is unspecified.
public long realWriteRemaining()
If the resource is closed, the returned value is unspecified.
public long readLimit()
If the resource is closed, the returned value is unspecified.
public long writeLimit()
If the resource is closed, the returned value is unspecified.
public long addressForRead(long offset, int buffer) throws UnsupportedOperationException, BufferUnderflowException, IllegalStateException
public ByteOrder byteOrder()
Copyright © 2022. All rights reserved.