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 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.
bytesStore, DISABLE_THREAD_SAFETY, isPresent, readPosition, writeLimit
referenceCounted, WARN_COUNT, WARN_NS
DEFAULT_BYTE_BUFFER_CAPACITY, MAX_CAPACITY, MAX_HEAP_CAPACITY
charToString
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<Bytes<U>,U> bytesStore) |
void |
bytesStore(@NotNull BytesStore<Bytes<U>,U> 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.
|
static BytesStore<Bytes<Void>,Void> |
copyOf(@NotNull Bytes<?> bytes)
Deprecated.
This method is to be removed in version x.26.
|
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) |
@NotNull NativeBytes |
writeSome(@NotNull Bytes<?> bytes)
Writes data from the specified
Bytes object into the output stream. |
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, internalNumberBuffer, 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, 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, clearUsedByThread, createdHere, disableReferenceTracing, enableReferenceTracing, refCount, referenceCountedUnmonitored, referenceId, release, releaseLast, removeReferenceChangeListener, reserve, reservedBy, 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, createCharToString, 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 IllegalStateException, IllegalArgumentException
store
- the BytesStore to be used for the newly constructed instancecapacity
- the capacity to be used for the newly constructed instanceIllegalStateException
- if an error occursIllegalArgumentException
- if an error occurspublic NativeBytes(@NotNull @NotNull BytesStore store) throws IllegalStateException, IllegalArgumentException
store
- the BytesStore to be used for the newly constructed instanceIllegalStateException
- if an error occursIllegalArgumentException
- if an error occurspublic 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.@Deprecated public static BytesStore<Bytes<Void>,Void> copyOf(@NotNull @NotNull Bytes<?> bytes) throws IllegalStateException
bytes
- The Bytes to copy.IllegalStateException
- If the Bytes cannot be copied.@NotNull public static <T> @NotNull NativeBytes<T> wrapWithNativeBytes(@NotNull @NotNull BytesStore<?,T> bs, long capacity) throws IllegalStateException, IllegalArgumentException
bs
- The BytesStore to wrap.capacity
- The capacity of the new NativeBytes instance.IllegalStateException
- If the BytesStore cannot be wrapped.IllegalArgumentException
- If the provided capacity is not valid.protected 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, IllegalStateException
writeCheckOffset
in class AbstractBytes<U>
BufferOverflowException
IllegalStateException
public void ensureCapacity(long desiredCapacity) throws IllegalArgumentException, IllegalStateException
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.IllegalStateException
- If the Bytes object is closed and needs to be resized.IllegalArgumentException
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<Bytes<U>,U> bytesStore)
bytesStore
in class AbstractBytes<U>
public void bytesStore(@NotNull @NotNull BytesStore<Bytes<U>,U> byteStore, long offset, long length) throws IllegalStateException, IllegalArgumentException, BufferUnderflowException
Byteable
bytesStore
in interface Byteable<Bytes<U>,U>
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 ByteStorenet.openhft.chronicle.core.io.ClosedIllegalStateException
- if it is closedIllegalArgumentException
- if the provided arguments are invalidBufferUnderflowException
- if the new memory section starts before the start of the ByteStoreIllegalStateException
@NotNull public @NotNull NativeBytes writeSome(@NotNull @NotNull Bytes<?> bytes) throws IllegalStateException
StreamingDataOutput
Bytes
object into the output stream. The amount of data written is
the minimum of the remaining data in the Bytes
object and the remaining space in the output stream.
The position of this output stream is updated accordingly, but the read position of the input data is not changed.bytes
- the Bytes
object from which data is read.IllegalStateException
- if releasedprotected long writeOffsetPositionMoved(long adding, long advance) throws BufferOverflowException, IllegalStateException
writeOffsetPositionMoved
in class AbstractBytes<U>
BufferOverflowException
IllegalStateException
@NotNull public @NotNull Bytes<U> writeByte(byte i8) throws BufferOverflowException, IllegalStateException
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.IllegalStateException
- if released@NotNull public @NotNull Bytes<U> writeLong(long i64) throws BufferOverflowException, IllegalStateException
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.IllegalStateException
- if releasedpublic long readRemaining()
If the resource is closed, the returned value is unspecified.
Copyright © 2023. All rights reserved.