U - The type of the object that this byte buffer is bound to.public class GuardedNativeBytes<U> extends NativeBytes<U>
This class extends the NativeBytes class and provides an additional layer of safety by tracking the raw primitives written to the byte buffer.
The purpose of this class is to facilitate the detection of inconsistencies during testing. When inconsistencies are detected, they can be corrected before the code is moved into production.
GuardedNativeBytes records the type of each primitive written into the bytes buffer (byte, short, int, long, float, double). This tracking enables validation of the consistency of data written and read, which is critical for data integrity.
Please note that while this class is very useful for ensuring data consistency during testing, it may introduce a performance overhead and thus not recommended to be used in a production environment.
capacitybytesStore, isPresent, readPosition, writeLimitreferenceCounted, WARN_COUNT, WARN_NSDEFAULT_BYTE_BUFFER_CAPACITY, MAX_CAPACITY, MAX_HEAP_CAPACITYJAVA9_STRING_CODER_LATIN, JAVA9_STRING_CODER_UTF16| Constructor and Description |
|---|
GuardedNativeBytes(@NotNull BytesStore<?,?> store,
long capacity)
Constructs a new GuardedNativeBytes instance backed by the specified BytesStore and with the specified capacity.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
bytesStore(@NotNull BytesStore<?,U> bytesStore) |
byte |
rawReadByte()
Reads a raw byte value from the input stream.
|
int |
rawReadInt()
Reads a 32-bit integer value from the input stream without performing boundary checks.
|
Bytes<U> |
rawWriteByte(byte i8)
Writes a byte to the data stream without any additional checks or transformations.
|
Bytes<U> |
rawWriteInt(int i)
Writes an integer to the data stream without any additional checks or transformations.
|
byte |
readByte()
Reads a byte value from the input stream.
|
double |
readDouble()
Reads a 64-bit floating-point number from the input stream.
|
float |
readFloat()
Reads a 32-bit floating-point number from the input stream.
|
int |
readInt()
Reads a 32-bit integer value from the input stream.
|
long |
readLong()
Reads a 64-bit long value from the input stream.
|
short |
readShort()
Reads a 16-bit short value from the input stream.
|
long |
readStopBit()
Reads a variable-length integer encoded using the stop bit encoding.
|
char |
readStopBitChar()
Reads a variable-length character encoded using the stop bit encoding.
|
int |
readUnsignedByte()
Reads the next unsigned 8-bit value from the input stream.
|
@NotNull String |
toHexString()
Creates and returns a new String representing the contents of this Bytes object in hexadecimal form,
with comments describing the meaning of the bytes.
|
@NotNull Bytes<U> |
writeByte(byte i8)
Writes a byte to the data stream.
|
@NotNull Bytes<U> |
writeDouble(double d)
Writes a double-precision floating-point number to the data stream.
|
@NotNull Bytes<U> |
writeFloat(float f)
Writes a floating-point number to the data stream.
|
BytesOut<U> |
writeHexDumpDescription(CharSequence comment)
Add comment as appropriate for the toHexString format
|
@NotNull Bytes<U> |
writeInt(int i)
Writes an integer to the data stream.
|
@NotNull Bytes<U> |
writeLong(long i64)
Writes a long integer to the data stream.
|
@NotNull Bytes<U> |
writeShort(short i16)
Writes a short integer to the data stream.
|
@NotNull Bytes<U> |
writeStopBit(char x)
Writes a stop bit encoded char to the data stream.
|
@NotNull Bytes<U> |
writeStopBit(long x)
Writes a stop bit encoded long to the data stream.
|
areNewGuarded, bytesStore, capacity, ensureCapacity, isElastic, isEqual, maxCapacityFor, nativeBytes, nativeBytes, readRemaining, resetNewGuarded, setNewGuarded, wrapWithNativeBytes, writeCheckOffset, writeOffsetPositionMovedappend, 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, writeacquireUncheckedInput, 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, readCheckOffset, readDouble, readFloat, readInt, readLimit, readLimit, readLong, readOffsetPositionMoved, readPosition, readPosition, readPositionForHeader, readShort, readSkip, readUnsignedByte, readVolatileByte, readVolatileInt, readVolatileInt, readVolatileLong, readVolatileShort, safeCopySize, start, startsWith, testAndSetInt, uncheckedReadSkipBackOne, uncheckedReadSkipOne, uncheckedReadUnsignedByte, uncheckedWritePosition, underlyingObject, unmonitor, write, write, write, write, write, write8bit, write8bit, write8bit, write8bit, writeBoolean, writeByte, writeDouble, writeDoubleAndInt, writeFloat, writeInt, writeIntAdv, writeLimit, writeLimit, writeLong, writeLongAdv, writeOffsetPositionMoved, writeOrderedInt, writeOrderedInt, writeOrderedLong, writeOrderedLong, writePosition, writePosition, writeShort, writeSkip, writeSome, writeVolatileByte, writeVolatileInt, writeVolatileLong, writeVolatileShortaddReferenceChangeListener, assertReferencesReleased, backgroundPerformRelease, canReleaseInBackground, createdHere, disableReferenceTracing, enableReferenceTracing, refCount, referenceCountedUnmonitored, referenceId, release, releaseLast, removeReferenceChangeListener, reserve, reserveTransfer, singleThreadedCheckDisabled, singleThreadedCheckReset, threadSafetyCheck, throwExceptionIfNotReleased, throwExceptionIfReleased, tryReserve, unmonitor, warnAndReleaseIfNotReleasedclone, finalize, getClass, notify, notifyAll, wait, wait, waitaddress, bytesStore, lock, tryLockallocateDirect, 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, toString, toString, toString, unchecked, unchecked, unwrite, valueOf, wrapForRead, wrapForRead, wrapForWrite, wrapForWrite, write, writeMarshallableLength16addAndGetDouble, 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, zeroOutappend, append, write, write, writeBoolean, writeByte, writeInt24, writeOrderedDouble, writeOrderedFloat, writeUnsignedByte, writeUnsignedInt, writeUnsignedShort, writeUtf8, writeUtf8Limited, writeVolatileDouble, writeVolatileFloatchars, codePointsbytesMethodReader, bytesMethodReaderBuilder, readObjectcanReadDirect, compareUtf8, copyTo, fastHash, parseLong, peekVolatileInt, printable, readBoolean, readIncompleteLong, readUnsignedInt, readUnsignedInt24, readUnsignedShort, readUtf8, readUtf8Limited, readUtf8Limited, readVolatileDouble, readVolatileFloat, subBytes, toByteArrayparse8bit, parse8bit, parse8bit, parse8bit, parse8bit, parseBigDecimal, parseBoolean, parseBoolean, parseDouble, parseFlexibleLong, parseFloat, parseInt, parseLongDecimal, parseUtf8, parseUtf8, parseUtf8, reader, skipToinputStream, parseHexLong, parseUtf8, parseUtf8, rawReadLong, read, read, read, read, read8bit, read8bit, read8bit, readBigDecimal, readBigInteger, readBoolean, readChar, readEnum, readHistogram, readIncompleteLong, readInt24, readLimitToCapacity, readPositionRemaining, readPositionUnlimited, readStopBitDecimal, readStopBitDouble, readUnsignedInt, readUnsignedInt24, readUnsignedShort, readUtf8, readUtf8, readUtf8, readUtf8, readWithLength, readWithLength, readWithLength0, unsafeRead, unsafeReadObjectbytesMethodWriter, writeObjectappend, append, append, append, append8bit, append8bit, appendBase, appendBase16, appendBase16, appendDateMillis, appendDecimal, appendTimeMillis, writerappendUtf8, appendUtf8, appendUtf8, appendUtf8, copyFrom, outputStream, rawWriteLong, unsafeWrite, unsafeWriteObject, write, write, write, write8bit, write8bit, write8bit, writeBigDecimal, writeBigInteger, writeChar, writeEnum, writeHistogram, writeInt24, writePositionForHeader, writePositionRemaining, writeStopBit, writeStopBitDecimal, writeUnsignedByte, writeUnsignedInt, writeUnsignedInt24, writeUnsignedShort, writeUtf8, writeUtf8, writeWithLength, writeWithLengthprependadjustHexDumpIndentation, retainedHexDumpDescriptionpublic GuardedNativeBytes(@NotNull
@NotNull BytesStore<?,?> store,
long capacity)
throws IllegalStateException,
IllegalArgumentException
store - The backing BytesStore.capacity - The capacity of the new GuardedNativeBytes instance.IllegalArgumentException - If the capacity is negative or exceeds the limit of the backing store.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 wayIllegalStateExceptionpublic BytesOut<U> writeHexDumpDescription(CharSequence comment) throws IllegalStateException
HexDumpBytesDescriptioncomment - to add (or ignore)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 wayIllegalStateExceptionprotected void bytesStore(@NotNull
@NotNull BytesStore<?,U> bytesStore)
bytesStore in class NativeBytes<U>@NotNull public @NotNull Bytes<U> writeByte(byte i8) throws BufferOverflowException, IllegalStateException
StreamingDataOutputwriteByte in interface StreamingDataOutput<Bytes<U>>writeByte in class NativeBytes<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 wayIllegalStateExceptionpublic Bytes<U> rawWriteByte(byte i8) throws BufferOverflowException, IllegalStateException
StreamingDataOutputi8 - 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 wayIllegalStateExceptionpublic Bytes<U> rawWriteInt(int i) throws BufferOverflowException, IllegalStateException
StreamingDataOutputi - The 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 wayIllegalStateExceptionpublic byte readByte()
throws IllegalStateException
StreamingDataInputreadByte in interface StreamingDataInput<Bytes<U>>readByte in class AbstractBytes<U>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 wayIllegalStateExceptionpublic byte rawReadByte()
throws IllegalStateException
StreamingDataInputreadByte() is that the latter might perform additional processing or checks.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 wayIllegalStateExceptionpublic int rawReadInt()
throws IllegalStateException,
BufferUnderflowException
StreamingDataInputnet.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 wayBufferUnderflowException - If there's not enough data to readIllegalStateExceptionpublic int readUnsignedByte()
throws IllegalStateException
StreamingDataInputreadUnsignedByte in interface StreamingDataInput<Bytes<U>>readUnsignedByte in class AbstractBytes<U>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 wayIllegalStateException@NotNull public @NotNull Bytes<U> writeShort(short i16) throws BufferOverflowException, IllegalStateException
StreamingDataOutputwriteShort in interface StreamingDataOutput<Bytes<U>>writeShort in class AbstractBytes<U>i16 - The short 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 wayIllegalStateExceptionpublic short readShort()
throws BufferUnderflowException,
IllegalStateException
StreamingDataInputreadShort in interface StreamingDataInput<Bytes<U>>readShort in class AbstractBytes<U>BufferUnderflowException - If there's not enough data to readnet.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 wayIllegalStateException@NotNull public @NotNull Bytes<U> writeStopBit(char x) throws BufferOverflowException, IllegalStateException
StreamingDataOutputx - The char value to be written to the data stream.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 wayIllegalStateException@NotNull public @NotNull Bytes<U> writeStopBit(long x) throws BufferOverflowException, IllegalStateException
StreamingDataOutputx - The long value to be written to the data stream.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 wayIllegalStateExceptionpublic long readStopBit()
throws net.openhft.chronicle.core.io.IORuntimeException,
IllegalStateException,
BufferUnderflowException
StreamingDataInputBytesInternal.readStopBit(this).net.openhft.chronicle.core.io.IORuntimeException - If an I/O error occursnet.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 wayBufferUnderflowException - If there's not enough data to readIllegalStateExceptionpublic char readStopBitChar()
throws net.openhft.chronicle.core.io.IORuntimeException,
IllegalStateException,
BufferUnderflowException
StreamingDataInputBytesInternal.readStopBitChar(this).net.openhft.chronicle.core.io.IORuntimeException - If an I/O error occursnet.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 wayBufferUnderflowException - If there's not enough data to readIllegalStateException@NotNull public @NotNull Bytes<U> writeInt(int i) throws BufferOverflowException, IllegalStateException
StreamingDataOutputwriteInt in interface StreamingDataOutput<Bytes<U>>writeInt in class AbstractBytes<U>i - The 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 wayIllegalStateExceptionpublic int readInt()
throws BufferUnderflowException,
IllegalStateException
StreamingDataInputreadInt in interface StreamingDataInput<Bytes<U>>readInt in class AbstractBytes<U>BufferUnderflowException - If there's not enough data to readnet.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 wayIllegalStateException@NotNull public @NotNull Bytes<U> writeLong(long i64) throws BufferOverflowException, IllegalStateException
StreamingDataOutputwriteLong in interface StreamingDataOutput<Bytes<U>>writeLong in class NativeBytes<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 wayIllegalStateExceptionpublic long readLong()
throws BufferUnderflowException,
IllegalStateException
StreamingDataInputreadLong in interface StreamingDataInput<Bytes<U>>readLong in class AbstractBytes<U>BufferUnderflowException - If there's not enough data to readnet.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 wayIllegalStateException@NotNull public @NotNull Bytes<U> writeFloat(float f) throws BufferOverflowException, IllegalStateException
StreamingDataOutputwriteFloat in interface StreamingDataOutput<Bytes<U>>writeFloat in class AbstractBytes<U>f - The floating-point number 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 wayIllegalStateExceptionpublic float readFloat()
throws BufferUnderflowException,
IllegalStateException
StreamingDataInputreadFloat in interface StreamingDataInput<Bytes<U>>readFloat in class AbstractBytes<U>BufferUnderflowException - If there's not enough data to readnet.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 wayIllegalStateException@NotNull public @NotNull Bytes<U> writeDouble(double d) throws BufferOverflowException, IllegalStateException
StreamingDataOutputwriteDouble in interface StreamingDataOutput<Bytes<U>>writeDouble in class AbstractBytes<U>d - The double-precision floating-point number 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 wayIllegalStateExceptionpublic double readDouble()
throws BufferUnderflowException,
IllegalStateException
StreamingDataInputreadDouble in interface StreamingDataInput<Bytes<U>>readDouble in class AbstractBytes<U>BufferUnderflowException - If there's not enough data to readnet.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 wayIllegalStateException@NotNull public @NotNull String toHexString()
BytesreadPosition()
and encodes at most 1024 bytes.
Each line of the output string contains hexadecimal representation of 16 bytes, followed by comments describing the meaning of those bytes.
For example, if the Bytes object contains bytes representing the ASCII string "VMH", the output would be similar to this:
c3 76 6d 68 # vmh: b6 03 56 4d 48 # VMH
This is assumed to be used to print the contents on a best effort basis. If an Error occurs it will be returned in the String.
Copyright © 2024. All rights reserved.