public class UncheckedBytes<U> extends AbstractBytes<U>
Warning: Using this class improperly can result in IndexOutOfBoundsException being thrown or worse, it can corrupt your data, cause JVM crashes, or produce other undefined behavior.
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 |
---|
UncheckedBytes(@NotNull Bytes<?> underlyingBytes)
Constructs an UncheckedBytes instance by wrapping around the provided Bytes object.
|
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()
Creates and returns a deep copy of this Bytes object, including the data between
RandomCommon.readPosition() and RandomCommon.readLimit() . |
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() . |
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)
Skips the specified number of bytes by advancing the read position.
|
void |
setBytes(@NotNull Bytes<?> bytes)
Sets the underlying Bytes instance for this UncheckedBytes.
|
boolean |
unchecked()
Checks whether this Bytes object operates in an unchecked mode.
|
@NotNull Bytes<U> |
unchecked(boolean unchecked)
Creates and returns a new Bytes which is optionally unchecked as indicated by the provided
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> |
write(@NotNull RandomDataInput bytes,
long offset,
long length)
Writes the specified number of bytes from the provided
RandomDataInput object 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 limit for writing to the data stream.
|
protected long |
writeOffsetPositionMoved(long adding,
long advance) |
@NotNull Bytes<U> |
writePosition(long position)
Sets the current write position in the data stream.
|
@NotNull Bytes<U> |
writeSkip(long bytesToSkip)
Skips a specified number of bytes from the current write position in the data stream.
|
@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, 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, 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
allocateDirect, allocateDirect, 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, writeMarshallableLength16
addAndGetDouble, 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, 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, findByte, parseLong, peekVolatileInt, printable, readBoolean, readIncompleteLong, readUnsignedInt, readUnsignedInt24, readUnsignedShort, readUtf8, readUtf8Limited, readUtf8Limited, readVolatileDouble, readVolatileFloat, subBytes, toByteArray, toTemporaryDirectByteBuffer
parse8bit, parse8bit, parse8bit, parse8bit, parse8bit, parseBigDecimal, parseBoolean, parseBoolean, parseDouble, parseFlexibleLong, parseFloat, parseInt, parseLong, parseLongDecimal, parseUtf8, parseUtf8, parseUtf8, reader, skipTo
inputStream, 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, unsafeReadObject, unsafeReadObject
bytesMethodWriter, writeObject
append, append, append, append, append, append8bit, append8bit, append8bit, append8bit, appendBase, appendBase16, appendBase16, appendDateMillis, appendDecimal, appendTimeMillis, writer
appendUtf8, 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, writeWithLength
prepend
adjustHexDumpIndentation, retainedHexDumpDescription, writeHexDumpDescription
public UncheckedBytes(@NotNull @NotNull Bytes<?> underlyingBytes) throws IllegalStateException
underlyingBytes
- the Bytes object to wrap aroundnet.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 void setBytes(@NotNull @NotNull Bytes<?> bytes) throws IllegalStateException
bytes
- the new underlying Bytes instancenet.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 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.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 wayIllegalArgumentException
IllegalStateException
@NotNull public @NotNull Bytes<U> unchecked(boolean unchecked)
Bytes
unchecked
.
This allows bounds checks to be turned off.
Note: this means that the result is no longer elastic, even if this
is elastic.
Note: It is only possible to go from a checked Bytes to an unchecked bytes and not vice versa.
unchecked
- if true, minimal bounds checks will be performedpublic boolean unchecked()
Bytes
When 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)
StreamingDataInput
readPosition
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)
StreamingDataInput
readLimit
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)
StreamingDataOutput
writePosition
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)
StreamingDataInput
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)
StreamingDataOutput
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)
StreamingDataOutput
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()
Bytes
RandomCommon.readPosition()
and RandomCommon.readLimit()
.
The copy will have its own separate storage and state, and modifications to the copy will not affect the original Bytes object, and vice versa.
public boolean isElastic()
Bytes
Bytes.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 RandomDataInput bytes, long offset, long length) throws BufferOverflowException, IllegalArgumentException, IllegalStateException, BufferUnderflowException
StreamingDataOutput
RandomDataInput
object into the output stream,
starting from the given read offset.
The position of this output stream is updated accordingly, but the read position of the input data is not changed.bytes
- the RandomDataInput
from which data is read.offset
- the offset at which reading from the RandomDataInput
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> write(@NotNull @NotNull BytesStore<?,?> bytes, long offset, long length) throws BufferOverflowException, IllegalArgumentException, IllegalStateException, BufferUnderflowException
StreamingDataOutput
BytesStore
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
ByteStringAppender
cs
- 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
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.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
StreamingDataOutput
text
- 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
StreamingDataOutput
chars
- 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 wayIllegalArgumentException
IllegalStateException
Copyright © 2024. All rights reserved.