public class UncheckedBytes<U> extends AbstractBytes<U>
Bytes instance that bypasses most bounds
checks on read and write operations. Intended for performance critical code
where the caller guarantees that all offsets are valid.
Warning: misuse can corrupt data or crash the JVM.
bytesStore, 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 |
|---|
UncheckedBytes(@NotNull Bytes<?> underlyingBytes)
Constructs an unchecked view over
underlyingBytes. |
| Modifier and Type | Method and Description |
|---|---|
@NotNull Bytes<U> |
append8bit(@NotNull CharSequence cs)
Appends a String to the Bytes in ISO-8859-1.
|
@NotNull Bytes<U> |
appendUtf8(char[] chars,
int offset,
int length)
Appends a UTF-8 encoded CharSequence to this output stream from a specific offset and length.
|
@NotNull BytesStore<Bytes<U>,U> |
copy()
Unsupported for unchecked views as copying would reintroduce checks.
|
void |
ensureCapacity(long desiredCapacity)
Delegates capacity checks to the wrapped instance and updates this view
if the underlying store changes.
|
boolean |
isElastic()
Checks if this Bytes object is elastic, meaning it can dynamically resize when more data is written
than its current
Bytes.realCapacity(). |
protected long |
prewriteOffsetPositionMoved(long subtracting) |
protected void |
readCheckOffset(long offset,
long adding,
boolean given) |
@NotNull Bytes<U> |
readLimit(long limit)
Sets the read limit of this StreamingDataInput.
|
protected long |
readOffsetPositionMoved(long adding) |
@NotNull Bytes<U> |
readPosition(long position)
Sets the read position of this StreamingDataInput.
|
@NotNull Bytes<U> |
readSkip(long bytesToSkip)
Advances the read position by
bytesToSkip. |
void |
setBytes(@NotNull Bytes<?> bytes)
Replaces the wrapped
Bytes instance. |
boolean |
unchecked()
Checks whether this Bytes object operates in an unchecked mode.
|
@NotNull Bytes<U> |
unchecked(boolean unchecked)
Always returns this instance as it is already unchecked.
|
@NotNull Bytes<U> |
write(@NotNull BytesStore<?,?> bytes,
long offset,
long length)
Writes the specified number of bytes from the provided
BytesStore into the output stream,
starting from the given read offset. |
@NotNull Bytes<U> |
writeByte(byte i8)
Writes a byte to the data stream.
|
protected void |
writeCheckOffset(long offset,
long adding) |
@NotNull Bytes<U> |
writeLimit(long limit)
Sets the maximum writeable offset.
|
protected long |
writeOffsetPositionMoved(long adding,
long advance) |
@NotNull Bytes<U> |
writePosition(long position)
Sets the current write position.
|
@NotNull Bytes<U> |
writeSkip(long bytesToSkip)
Advances or rewinds the write position by
bytesToSkip. |
@NotNull Bytes<U> |
writeUtf8(@Nullable String text)
Writes a UTF-8 encoded String to the data stream.
|
acquireUncheckedInput, addressForRead, addressForWrite, addressForWritePosition, append, append, append, append, append, append, appendAndReturnLength, byteCheckSum, byteCheckSum, byteCheckSum, bytesStore, bytesStore, canReadDirect, canWriteDirect, capacity, 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, prewriteShort, read, read, readByte, readByte, readDouble, readDouble, readFloat, readFloat, readInt, readInt, readLimit, readLong, readLong, readPosition, readPositionForHeader, readShort, readShort, readUnsignedByte, readUnsignedByte, readVolatileByte, readVolatileInt, readVolatileInt, readVolatileLong, readVolatileLong, readVolatileShort, realCapacity, safeCopySize, start, startsWith, testAndSetInt, toString, uncheckedReadSkipBackOne, uncheckedReadSkipOne, uncheckedReadUnsignedByte, uncheckedWritePosition, underlyingObject, unmonitor, write, write, write, write, write, write8bit, write8bit, write8bit, write8bit, writeBoolean, writeByte, writeDouble, writeDouble, writeDoubleAndInt, writeFloat, writeFloat, writeInt, writeInt, writeIntAdv, writeLimit, writeLong, writeLong, writeLongAdv, writeOffsetPositionMoved, writeOrderedInt, writeOrderedInt, writeOrderedLong, writeOrderedLong, writePosition, writeShort, writeShort, 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, waitallocateDirect, allocateDirect, allocateElastic, allocateElastic, allocateElasticDirect, allocateElasticDirect, allocateElasticOnHeap, allocateElasticOnHeap, bytesForRead, bytesForWrite, copyTo, copyTo, directFrom, elasticByteBuffer, elasticByteBuffer, elasticByteBuffer, elasticHeapByteBuffer, elasticHeapByteBuffer, empty, forFieldGroup, from, from, fromDirect, fromHexString, indexOf, indexOf, isClear, isEqual, readMarshallableLength16, readWithLength, readWrite, safeLimit, sharedMemory, toHexString, toHexString, toHexString, toString, toString, toString, unwrite, valueOf, wrapForRead, wrapForRead, wrapForWrite, wrapForWrite, write, writeMarshallableLength16addAndGetDouble, addAndGetDoubleNotAtomic, addAndGetFloat, addAndGetFloatNotAtomic, addAndGetInt, addAndGetIntNotAtomic, addAndGetLong, addAndGetShortNotAtomic, addAndGetUnsignedByteNotAtomic, charAt, cipher, cipher, compareAndSwapDouble, compareAndSwapFloat, contentEquals, elasticByteBuffer, endsWith, equalBytes, follow, forFields, from, hash, inside, inside, isEmpty, isEqual, lazyNativeBytesStoreWithFixedCapacity, nativePointer, nativeStore, nativeStoreFrom, nativeStoreWithFixedCapacity, startsWith, subSequence, to8bitString, toDebugString, toDebugString, toUtf8String, 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, findByte, parseLong, peekVolatileInt, printable, readBoolean, readIncompleteLong, readUnsignedInt, readUnsignedInt24, readUnsignedShort, readUtf8, readUtf8Limited, readUtf8Limited, readVolatileDouble, readVolatileFloat, subBytes, toByteArray, toTemporaryDirectByteBufferparse8bit, parse8bit, parse8bit, parse8bit, parse8bit, parseBigDecimal, parseBoolean, parseBoolean, parseDouble, parseFlexibleLong, parseFloat, parseInt, parseLong, parseLongDecimal, parseUtf8, parseUtf8, parseUtf8, reader, skipToinputStream, parseHexLong, parseUtf8, parseUtf8, rawReadByte, rawReadInt, rawReadLong, read, 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, unsafeReadObjectbytesMethodWriter, writeObjectappend, append, append, append, append, append8bit, append8bit, append8bit, append8bit, appendBase, appendBase16, appendBase16, appendDateMillis, appendDecimal, appendTimeMillis, writerappendUtf8, appendUtf8, appendUtf8, appendUtf8, appendUtf8, copyFrom, outputStream, rawWriteByte, rawWriteInt, rawWriteLong, unsafeWrite, unsafeWriteObject, write, write, write, write8bit, write8bit, write8bit, writeBigDecimal, writeBigInteger, writeChar, writeEnum, writeHistogram, writeInt24, writePositionForHeader, writePositionRemaining, writeStopBit, writeStopBit, writeStopBit, writeStopBitDecimal, writeUnsignedByte, writeUnsignedInt, writeUnsignedInt24, writeUnsignedShort, writeUtf8, writeWithLength, writeWithLengthprependadjustHexDumpIndentation, retainedHexDumpDescription, writeHexDumpDescriptionpublic UncheckedBytes(@NotNull
@NotNull Bytes<?> underlyingBytes)
throws IllegalStateException
underlyingBytes. The positions
and limits of the wrapped bytes are inherited.underlyingBytes - the Bytes instance to wrapnet.openhft.chronicle.core.io.ClosedIllegalStateException - if the resource has been released or closednet.openhft.chronicle.core.io.ThreadingIllegalStateException - if accessed by multiple threads in an unsafe wayIllegalStateExceptionpublic void setBytes(@NotNull
@NotNull Bytes<?> bytes)
throws IllegalStateException
Bytes instance. The current store is
released and the new one reserved.bytes - the new underlying bytesnet.openhft.chronicle.core.io.ClosedIllegalStateException - if the resource has been released or closednet.openhft.chronicle.core.io.ThreadingIllegalStateException - if accessed by multiple threads in an unsafe wayIllegalStateExceptionpublic void ensureCapacity(long desiredCapacity)
throws IllegalArgumentException,
IllegalStateException
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 wayIllegalArgumentExceptionIllegalStateException@NotNull public @NotNull Bytes<U> unchecked(boolean unchecked)
unchecked - if true, minimal bounds checks will be performedpublic boolean unchecked()
BytesWhen a Bytes object is unchecked, it performs minimal or no bounds checking on read and write operations. This can improve performance but may result in undefined behavior if attempting to access out-of-bounds elements.
true if this Bytes object operates in unchecked mode; false otherwise.protected void writeCheckOffset(long offset,
long adding)
writeCheckOffset in class AbstractBytes<U>protected void readCheckOffset(long offset,
long adding,
boolean given)
readCheckOffset in class AbstractBytes<U>@NotNull public @NotNull Bytes<U> readPosition(long position)
StreamingDataInputreadPosition in interface StreamingDataInput<Bytes<U>>readPosition in class AbstractBytes<U>position - the new read position, must be non-negative@NotNull public @NotNull Bytes<U> readLimit(long limit)
StreamingDataInputreadLimit in interface StreamingDataInput<Bytes<U>>readLimit in class AbstractBytes<U>limit - the new read limit, must be non-negative@NotNull public @NotNull Bytes<U> writePosition(long position)
StreamingDataOutputwritePosition in interface StreamingDataOutput<Bytes<U>>writePosition in class AbstractBytes<U>position - The new write position. It must be a non-negative number.@NotNull public @NotNull Bytes<U> readSkip(long bytesToSkip)
StreamingDataInputbytesToSkip. If
lenient mode is active, attempts to move beyond
the read limit are capped at the limit without throwing.readSkip in interface StreamingDataInput<Bytes<U>>readSkip in class AbstractBytes<U>bytesToSkip - the number of bytes to skip@NotNull public @NotNull Bytes<U> writeSkip(long bytesToSkip)
StreamingDataOutputbytesToSkip. The result
must remain within RandomCommon.writeLimit().writeSkip in interface StreamingDataOutput<Bytes<U>>writeSkip in class AbstractBytes<U>bytesToSkip - The number of bytes to skip. This can be a negative number to move the
position backward.@NotNull public @NotNull Bytes<U> writeLimit(long limit)
StreamingDataOutputBufferOverflowException.writeLimit in interface StreamingDataOutput<Bytes<U>>writeLimit in class AbstractBytes<U>limit - The new write limit. It must be a non-negative number.@NotNull public @NotNull BytesStore<Bytes<U>,U> copy()
public boolean isElastic()
BytesBytes.realCapacity().
Elastic Bytes objects can automatically grow to accommodate additional data, whereas non-elastic ones have a fixed capacity.
protected long readOffsetPositionMoved(long adding)
readOffsetPositionMoved in class AbstractBytes<U>protected long writeOffsetPositionMoved(long adding,
long advance)
writeOffsetPositionMoved in class AbstractBytes<U>protected long prewriteOffsetPositionMoved(long subtracting)
throws BufferOverflowException
prewriteOffsetPositionMoved in class AbstractBytes<U>BufferOverflowException@NotNull public @NotNull Bytes<U> write(@NotNull @NotNull BytesStore<?,?> bytes, long offset, long length) throws BufferOverflowException, IllegalArgumentException, IllegalStateException, BufferUnderflowException
StreamingDataOutputBytesStore into the output stream,
starting from the given read offset. It ensures that the output stream has enough capacity
to accommodate the incoming bytes. The position of this output stream is updated accordingly,
but the read position of the input data is not changed.bytes - the BytesStore from which data is read.offset - the offset at which reading from the BytesStore starts.length - the number of bytes to write.BufferOverflowException - If there is not enough space left in the output stream.IllegalArgumentException - If the readOffset or length are invalid.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 is not enough data available in the input.IllegalStateException@NotNull public @NotNull Bytes<U> append8bit(@NotNull @NotNull CharSequence cs) throws BufferOverflowException, BufferUnderflowException, IllegalStateException
ByteStringAppendercs - the CharSequence to appendBufferOverflowException - If the string is too large to write in the capacity availableBufferUnderflowException - If the capacity of the underlying buffer was exceedednet.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.IllegalStateException@NotNull public @NotNull Bytes<U> writeByte(byte i8) throws BufferOverflowException, IllegalStateException
StreamingDataOutputwriteByte 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 wayIllegalStateException@NotNull public @NotNull Bytes<U> writeUtf8(@Nullable @Nullable String text) throws BufferOverflowException, IllegalStateException
StreamingDataOutputtext - The string to be written. Can be null.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> appendUtf8(char[] chars, int offset, int length) throws BufferOverflowException, IllegalArgumentException, IllegalStateException
StreamingDataOutputchars - The CharSequence to be appended.offset - The offset from which to start writing the CharSequence.length - The number of characters from the CharSequence to write.BufferOverflowException - If there is not enough space left in the output stream.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 wayIllegalArgumentExceptionIllegalStateExceptionCopyright © 2026 Chronicle Software Ltd. All rights reserved.