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.
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 |
---|
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 |
---|---|
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 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.
|
@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, bytesStore, capacity, copyOf, ensureCapacity, isElastic, isEqual, maxCapacityFor, nativeBytes, nativeBytes, readRemaining, resetNewGuarded, setNewGuarded, wrapWithNativeBytes, writeCheckOffset, writeOffsetPositionMoved, writeSome
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, 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, 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, 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, writeHexDumpDescription
public GuardedNativeBytes(@NotNull @NotNull BytesStore<?,?> store, long capacity) throws IllegalStateException, IllegalArgumentException
store
- The backing BytesStore.capacity
- The capacity of the new GuardedNativeBytes instance.IllegalStateException
- If the backing store has been released.IllegalArgumentException
- If the capacity is negative or exceeds the limit of the backing store.@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.IllegalStateException
- if releasedpublic Bytes<U> rawWriteByte(byte i8) throws BufferOverflowException, IllegalStateException
StreamingDataOutput
i8
- The byte to be written.BufferOverflowException
- if there is insufficient space in the buffer.IllegalStateException
- if releasedpublic Bytes<U> rawWriteInt(int i) throws BufferOverflowException, IllegalStateException
StreamingDataOutput
i
- The integer to be written.BufferOverflowException
- if there is insufficient space in the buffer.IllegalStateException
- if releasedpublic byte readByte() throws IllegalStateException
StreamingDataInput
readByte
in interface StreamingDataInput<Bytes<U>>
readByte
in class AbstractBytes<U>
IllegalStateException
- if a required state for this operation is not metpublic byte rawReadByte() throws IllegalStateException
StreamingDataInput
readByte()
is that the latter might perform additional processing or checks.IllegalStateException
- if a required state for this operation is not metpublic int rawReadInt() throws IllegalStateException, BufferUnderflowException
StreamingDataInput
IllegalStateException
- if a required state for this operation is not metBufferUnderflowException
- if there's not enough data to readpublic int readUnsignedByte() throws IllegalStateException
StreamingDataInput
readUnsignedByte
in interface StreamingDataInput<Bytes<U>>
readUnsignedByte
in class AbstractBytes<U>
IllegalStateException
- if a required state for this operation is not met@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.IllegalStateException
- if releasedpublic 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 readIllegalStateException
- if a required state for this operation is not met@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.IllegalStateException
- if released@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.IllegalStateException
- if releasedpublic 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 occursIllegalStateException
- if a required state for this operation is not metBufferUnderflowException
- if there's not enough data to readpublic 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 occursIllegalStateException
- if a required state for this operation is not metBufferUnderflowException
- if there's not enough data to read@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.IllegalStateException
- if releasedpublic 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 readIllegalStateException
- if a required state for this operation is not met@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.IllegalStateException
- if releasedpublic 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 readIllegalStateException
- if a required state for this operation is not met@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.IllegalStateException
- if releasedpublic 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 readIllegalStateException
- if a required state for this operation is not met@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.IllegalStateException
- if releasedpublic 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 readIllegalStateException
- if a required state for this operation is not metCopyright © 2023. All rights reserved.