U
- This represents the underlying type that the byte buffers are intended to represent.public class NativeBytes<U> extends VanillaBytes<U>
The class can be parameterized with a type <U> which represents the underlying type that the byte buffers are intended to represent. This provides a way to use NativeBytes for any type that can be represented as bytes.
Modifier and Type | Field and Description |
---|---|
protected long |
capacity |
bytesStore, isPresent, readPosition, writeLimit
referenceCounted, WARN_COUNT, WARN_NS
DEFAULT_BYTE_BUFFER_CAPACITY, MAX_CAPACITY, MAX_HEAP_CAPACITY
JAVA9_STRING_CODER_LATIN, JAVA9_STRING_CODER_UTF16
Constructor and Description |
---|
NativeBytes(@NotNull BytesStore<?,?> store)
Constructs a new instance of NativeBytes with the specified BytesStore and the store's capacity.
|
NativeBytes(@NotNull BytesStore<?,?> store,
long capacity)
Constructs a new instance of NativeBytes with the specified BytesStore and capacity.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
areNewGuarded()
Checks if new NativeBytes instances will be guarded or not.
|
protected void |
bytesStore(@NotNull BytesStore<?,U> bytesStore) |
void |
bytesStore(@NotNull BytesStore byteStore,
long offset,
long length)
Sets the reference to a data type that points to the underlying ByteStore.
|
long |
capacity()
Provides the maximum limit that can be set for the ByteStore.
|
void |
ensureCapacity(long desiredCapacity)
Ensures that this Bytes object has the capacity to accommodate the specified amount of data.
|
boolean |
isElastic()
Checks if this Bytes object is elastic, meaning it can dynamically resize when more data is written
than its current
Bytes.realCapacity() . |
boolean |
isEqual(long start,
long length,
String s)
Returns if a specified portion of this BytesStore is equal to a specified String.
|
protected static <T> long |
maxCapacityFor(@NotNull BytesStore<?,T> bs) |
static @NotNull NativeBytes<Void> |
nativeBytes()
Creates a new instance of NativeBytes with an empty BytesStore and maximum capacity.
|
static @NotNull NativeBytes<Void> |
nativeBytes(long initialCapacity)
Creates a new instance of NativeBytes with a specific initial capacity.
|
long |
readRemaining()
Calculates the number of bytes remaining that can be read from the current read position.
|
static void |
resetNewGuarded()
Resets the guarded state for new NativeBytes instances to its default value.
|
static boolean |
setNewGuarded(boolean guarded)
Sets the guarded state for new NativeBytes instances.
|
static <T> @NotNull NativeBytes<T> |
wrapWithNativeBytes(@NotNull BytesStore<?,T> bs,
long capacity)
Wraps the provided BytesStore with a new instance of NativeBytes with the specified capacity.
|
@NotNull Bytes<U> |
writeByte(byte i8)
Writes a byte to the data stream.
|
protected void |
writeCheckOffset(long offset,
long adding) |
@NotNull Bytes<U> |
writeLong(long i64)
Writes a long integer to the data stream.
|
protected long |
writeOffsetPositionMoved(long adding,
long advance) |
append, append8bit, append8bit, append8bit, append8bit0, appendUtf8, appendUtf8, byteCheckSum, bytesForRead, compareTo, copy, equalBytes, findByte, isEqual, maxSize, offset, optimisedWrite, parseLong, read, read8Bit, readVolatileLong, realCapacity, toString, toString0, toTemporaryDirectByteBuffer, vanillaBytes, wrap, write, write, write
acquireUncheckedInput, addressForRead, addressForWrite, addressForWritePosition, append, append, append, append, append, append, appendAndReturnLength, byteCheckSum, byteCheckSum, bytesStore, canReadDirect, canWriteDirect, clear, clearAndPad, compact, compareAndSwapInt, compareAndSwapLong, copyTo, decimaliser, decimaliser, equals, fpAppend0, fpAppend0, hashCode, isDirectMemory, isImmutableEmptyByteStore, lastDecimalPlaces, lastDecimalPlaces, lastNumberHadDigits, lastNumberHadDigits, length, lenient, lenient, move, nativeRead, nativeWrite, peekUnsignedByte, peekUnsignedByte, performRelease, prewrite, prewrite, prewriteByte, prewriteInt, prewriteLong, prewriteOffsetPositionMoved, prewriteShort, read, read, readByte, readByte, readCheckOffset, readDouble, readDouble, readFloat, readFloat, readInt, readInt, readLimit, readLimit, readLong, readLong, readOffsetPositionMoved, readPosition, readPosition, readPositionForHeader, readShort, readShort, readSkip, readUnsignedByte, readUnsignedByte, readVolatileByte, readVolatileInt, readVolatileInt, readVolatileLong, readVolatileShort, safeCopySize, start, startsWith, testAndSetInt, uncheckedReadSkipBackOne, uncheckedReadSkipOne, uncheckedReadUnsignedByte, uncheckedWritePosition, underlyingObject, unmonitor, write, write, write, write, write, write, write8bit, write8bit, write8bit, write8bit, writeBoolean, writeByte, writeDouble, writeDouble, writeDoubleAndInt, writeFloat, writeFloat, writeInt, writeInt, writeIntAdv, writeLimit, writeLimit, writeLong, writeLongAdv, writeOffsetPositionMoved, writeOrderedInt, writeOrderedInt, writeOrderedLong, writeOrderedLong, writePosition, writePosition, writeShort, writeShort, writeSkip, writeSome, writeVolatileByte, writeVolatileInt, writeVolatileLong, writeVolatileShort
addReferenceChangeListener, assertReferencesReleased, backgroundPerformRelease, canReleaseInBackground, createdHere, disableReferenceTracing, enableReferenceTracing, refCount, referenceCountedUnmonitored, referenceId, release, releaseLast, removeReferenceChangeListener, reserve, reserveTransfer, singleThreadedCheckDisabled, singleThreadedCheckReset, threadSafetyCheck, throwExceptionIfNotReleased, throwExceptionIfReleased, tryReserve, unmonitor, warnAndReleaseIfNotReleased
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
address, bytesStore, lock, tryLock
allocateDirect, allocateDirect, allocateElasticDirect, allocateElasticDirect, allocateElasticOnHeap, allocateElasticOnHeap, bytesForWrite, copyTo, copyTo, directFrom, elasticByteBuffer, elasticByteBuffer, elasticByteBuffer, elasticHeapByteBuffer, elasticHeapByteBuffer, empty, forFieldGroup, from, from, fromDirect, fromHexString, indexOf, indexOf, isClear, readMarshallableLength16, readWithLength, readWrite, safeLimit, sharedMemory, toHexString, toHexString, toHexString, toString, toString, toString, unchecked, unchecked, unwrite, valueOf, wrapForRead, wrapForRead, wrapForWrite, wrapForWrite, write, writeMarshallableLength16
addAndGetDouble, addAndGetDoubleNotAtomic, addAndGetFloat, addAndGetFloatNotAtomic, addAndGetInt, addAndGetIntNotAtomic, addAndGetLong, addAndGetShortNotAtomic, addAndGetUnsignedByteNotAtomic, charAt, cipher, cipher, compareAndSwapDouble, compareAndSwapFloat, contentEquals, elasticByteBuffer, endsWith, follow, forFields, from, hash, inside, inside, isEmpty, lazyNativeBytesStoreWithFixedCapacity, nativePointer, nativeStore, nativeStoreFrom, nativeStoreWithFixedCapacity, startsWith, subSequence, to8bitString, toDebugString, toDebugString, wrap, wrap, wrap, writeMaxInt, writeMaxLong, zeroOut
append, append, write, write, writeBoolean, writeByte, writeInt24, writeOrderedDouble, writeOrderedFloat, writeUnsignedByte, writeUnsignedInt, writeUnsignedShort, writeUtf8, writeUtf8Limited, writeVolatileDouble, writeVolatileFloat
chars, codePoints
bytesMethodReader, bytesMethodReaderBuilder, readObject
canReadDirect, compareUtf8, copyTo, fastHash, parseLong, peekVolatileInt, printable, readBoolean, readIncompleteLong, readUnsignedInt, readUnsignedInt24, readUnsignedShort, readUtf8, readUtf8Limited, readUtf8Limited, readVolatileDouble, readVolatileFloat, subBytes, toByteArray
parse8bit, parse8bit, parse8bit, parse8bit, parse8bit, parseBigDecimal, parseBoolean, parseBoolean, parseDouble, parseFlexibleLong, parseFloat, parseInt, parseLongDecimal, parseUtf8, parseUtf8, parseUtf8, reader, skipTo
inputStream, parseHexLong, parseUtf8, parseUtf8, rawReadByte, rawReadInt, rawReadLong, read, read, read, read, read8bit, read8bit, read8bit, readBigDecimal, readBigInteger, readBoolean, readChar, readEnum, readHistogram, readIncompleteLong, readInt24, readLimitToCapacity, readPositionRemaining, readPositionUnlimited, readStopBit, readStopBitChar, readStopBitDecimal, readStopBitDouble, readUnsignedInt, readUnsignedInt24, readUnsignedShort, readUtf8, readUtf8, readUtf8, readUtf8, readWithLength, readWithLength, readWithLength0, unsafeRead, unsafeReadObject, unsafeReadObject
bytesMethodWriter, writeObject
append, append, append, append, append8bit, append8bit, appendBase, appendBase16, appendBase16, appendDateMillis, appendDecimal, appendTimeMillis, writer
appendUtf8, appendUtf8, appendUtf8, appendUtf8, copyFrom, outputStream, rawWriteByte, rawWriteInt, rawWriteLong, unsafeWrite, unsafeWriteObject, unsafeWriteObject, write, write, write, write8bit, write8bit, write8bit, writeBigDecimal, writeBigInteger, writeChar, writeEnum, writeHistogram, writeInt24, writePositionForHeader, writePositionRemaining, writeStopBit, writeStopBit, writeStopBit, writeStopBitDecimal, writeUnsignedByte, writeUnsignedInt, writeUnsignedInt24, writeUnsignedShort, writeUtf8, writeUtf8, writeWithLength
prepend
adjustHexDumpIndentation, retainedHexDumpDescription, writeHexDumpDescription
public NativeBytes(@NotNull @NotNull BytesStore<?,?> store, long capacity) throws IllegalArgumentException, net.openhft.chronicle.core.io.ClosedIllegalStateException
store
- the BytesStore to be used for the newly constructed instancecapacity
- the capacity to be used for the newly constructed instancenet.openhft.chronicle.core.io.ClosedIllegalStateException
- If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException
- If this resource was accessed by multiple threads in an unsafe wayIllegalArgumentException
public NativeBytes(@NotNull @NotNull BytesStore<?,?> store) throws IllegalArgumentException, net.openhft.chronicle.core.io.ClosedIllegalStateException
store
- the BytesStore to be used for the newly constructed instancenet.openhft.chronicle.core.io.ClosedIllegalStateException
- If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException
- If this resource was accessed by multiple threads in an unsafe wayIllegalArgumentException
public static boolean areNewGuarded()
public static boolean setNewGuarded(boolean guarded)
guarded
- true to turn on guarding for new NativeBytes instances, false to turn it offpublic static void resetNewGuarded()
@NotNull public static @NotNull NativeBytes<Void> nativeBytes()
AssertionError
- If there's an error during the wrapping process.@NotNull public static @NotNull NativeBytes<Void> nativeBytes(long initialCapacity) throws IllegalArgumentException
initialCapacity
- The initial capacity of the NativeBytes instance.IllegalArgumentException
- If the initial capacity is not valid.AssertionError
- If there's an error during the wrapping process.@NotNull public static <T> @NotNull NativeBytes<T> wrapWithNativeBytes(@NotNull @NotNull BytesStore<?,T> bs, long capacity) throws net.openhft.chronicle.core.io.ClosedIllegalStateException, IllegalArgumentException
bs
- The BytesStore to wrap.capacity
- The capacity of the new NativeBytes instance.IllegalArgumentException
- If the provided capacity is not valid.net.openhft.chronicle.core.io.ClosedIllegalStateException
- If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException
- If this resource was accessed by multiple threads in an unsafe wayprotected static <T> long maxCapacityFor(@NotNull @NotNull BytesStore<?,T> bs)
public long capacity()
BytesStore
capacity
in interface BytesStore<Bytes<U>,U>
capacity
in class AbstractBytes<U>
protected void writeCheckOffset(long offset, long adding) throws BufferOverflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
writeCheckOffset
in class AbstractBytes<U>
BufferOverflowException
net.openhft.chronicle.core.io.ClosedIllegalStateException
net.openhft.chronicle.core.io.ThreadingIllegalStateException
public void ensureCapacity(long desiredCapacity) throws IllegalArgumentException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
Bytes
If this Bytes object is elastic and doesn't have enough capacity, it will be resized. If it is not
elastic and doesn't have enough capacity, a DecoratedBufferOverflowException
will be thrown.
desiredCapacity
- The minimum capacity, in bytes, that is required.net.openhft.chronicle.core.io.ClosedIllegalStateException
- If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException
- If this resource was accessed by multiple threads in an unsafe wayIllegalArgumentException
public boolean isElastic()
Bytes
Bytes.realCapacity()
.
Elastic Bytes objects can automatically grow to accommodate additional data, whereas non-elastic ones have a fixed capacity.
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 sprotected void bytesStore(@NotNull @NotNull BytesStore<?,U> bytesStore)
bytesStore
in class AbstractBytes<U>
public void bytesStore(@NotNull @NotNull BytesStore byteStore, long offset, long length) throws IllegalArgumentException, BufferUnderflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
Byteable
bytesStore
in interface Byteable
bytesStore
in class VanillaBytes<U>
byteStore
- the fixed-point ByteStoreoffset
- the offset within the ByteStore, indicating the starting point of the memory sectionlength
- the length of the memory section within the ByteStoreIllegalArgumentException
- If the provided arguments are invalidBufferUnderflowException
- If the new memory section starts before the start of the ByteStorenet.openhft.chronicle.core.io.ClosedIllegalStateException
- If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException
- If this resource was accessed by multiple threads in an unsafe wayprotected long writeOffsetPositionMoved(long adding, long advance) throws BufferOverflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
writeOffsetPositionMoved
in class AbstractBytes<U>
BufferOverflowException
net.openhft.chronicle.core.io.ClosedIllegalStateException
net.openhft.chronicle.core.io.ThreadingIllegalStateException
@NotNull public @NotNull Bytes<U> writeByte(byte i8) throws BufferOverflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
StreamingDataOutput
writeByte
in interface StreamingDataOutput<Bytes<U>>
writeByte
in class AbstractBytes<U>
i8
- The byte to be written.BufferOverflowException
- If there is insufficient space in the buffer.net.openhft.chronicle.core.io.ClosedIllegalStateException
- If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException
- If this resource was accessed by multiple threads in an unsafe way@NotNull public @NotNull Bytes<U> writeLong(long i64) throws BufferOverflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
StreamingDataOutput
writeLong
in interface StreamingDataOutput<Bytes<U>>
writeLong
in class AbstractBytes<U>
i64
- The long integer to be written.BufferOverflowException
- If there is insufficient space in the buffer.net.openhft.chronicle.core.io.ClosedIllegalStateException
- If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException
- If this resource was accessed by multiple threads in an unsafe waypublic long readRemaining()
If the resource is closed, the returned value is unspecified.
Copyright © 2024. All rights reserved.