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.
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 |
---|
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<Bytes<U>,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, copyOf, ensureCapacity, isElastic, isEqual, maxCapacityFor, nativeBytes, nativeBytes, readRemaining, resetNewGuarded, setNewGuarded, wrapWithNativeBytes, writeCheckOffset, writeOffsetPositionMoved
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, 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, write, 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, 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, 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, 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, unsafeReadObject, unsafeReadObject
bytesMethodWriter, writeObject
append, append, append, append, append8bit, append8bit, appendBase, appendBase16, appendBase16, appendDateMillis, appendDecimal, appendTimeMillis, writer
appendUtf8, appendUtf8, appendUtf8, appendUtf8, copyFrom, outputStream, rawWriteLong, unsafeWrite, unsafeWriteObject, unsafeWriteObject, write, write, write, write8bit, write8bit, write8bit, writeBigDecimal, writeBigInteger, writeChar, writeEnum, writeHistogram, writeInt24, writePositionForHeader, writePositionRemaining, writeStopBit, writeStopBitDecimal, writeUnsignedByte, writeUnsignedInt, writeUnsignedInt24, writeUnsignedShort, writeUtf8, writeUtf8, writeWithLength
prepend
adjustHexDumpIndentation, retainedHexDumpDescription
public 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 wayIllegalStateException
public BytesOut<U> writeHexDumpDescription(CharSequence comment) throws IllegalStateException
HexDumpBytesDescription
comment
- 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 wayIllegalStateException
protected void bytesStore(@NotNull @NotNull BytesStore<Bytes<U>,U> bytesStore)
bytesStore
in class NativeBytes<U>
@NotNull public @NotNull Bytes<U> writeByte(byte i8) throws BufferOverflowException, IllegalStateException
StreamingDataOutput
writeByte
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 wayIllegalStateException
public Bytes<U> rawWriteByte(byte i8) throws BufferOverflowException, IllegalStateException
StreamingDataOutput
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 wayIllegalStateException
public Bytes<U> rawWriteInt(int i) throws BufferOverflowException, IllegalStateException
StreamingDataOutput
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 wayIllegalStateException
public byte readByte() throws IllegalStateException
StreamingDataInput
readByte
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 wayIllegalStateException
public byte rawReadByte() throws IllegalStateException
StreamingDataInput
readByte()
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 wayIllegalStateException
public int rawReadInt() throws IllegalStateException, BufferUnderflowException
StreamingDataInput
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 wayBufferUnderflowException
- If there's not enough data to readIllegalStateException
public int readUnsignedByte() throws IllegalStateException
StreamingDataInput
readUnsignedByte
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
StreamingDataOutput
writeShort
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 wayIllegalStateException
public short readShort() throws BufferUnderflowException, IllegalStateException
StreamingDataInput
readShort
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
StreamingDataOutput
x
- 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
StreamingDataOutput
x
- 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 wayIllegalStateException
public long readStopBit() throws net.openhft.chronicle.core.io.IORuntimeException, IllegalStateException, BufferUnderflowException
StreamingDataInput
BytesInternal.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 readIllegalStateException
public char readStopBitChar() throws net.openhft.chronicle.core.io.IORuntimeException, IllegalStateException, BufferUnderflowException
StreamingDataInput
BytesInternal.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
StreamingDataOutput
writeInt
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 wayIllegalStateException
public int readInt() throws BufferUnderflowException, IllegalStateException
StreamingDataInput
readInt
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
StreamingDataOutput
writeLong
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 wayIllegalStateException
public long readLong() throws BufferUnderflowException, IllegalStateException
StreamingDataInput
readLong
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
StreamingDataOutput
writeFloat
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 wayIllegalStateException
public float readFloat() throws BufferUnderflowException, IllegalStateException
StreamingDataInput
readFloat
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
StreamingDataOutput
writeDouble
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 wayIllegalStateException
public double readDouble() throws BufferUnderflowException, IllegalStateException
StreamingDataInput
readDouble
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()
Bytes
readPosition()
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 © 2023. All rights reserved.