B
- the type of ByteStringParser
which extends itself, allowing for method chaining.public interface ByteStringParser<B extends ByteStringParser<B>> extends StreamingDataInput<B>
The ByteStringParser
extends StreamingDataInput
, inheriting the capabilities
of reading and manipulating streams of binary data.
This interface is especially useful for reading and converting bytes into human-readable text or numerical representations. It includes methods for parsing numbers with flexible formatting, reading text with specified character encoding, and utilities for dealing with character termination conditions.
Example use cases include reading and parsing data from binary communication protocols, files, or any other source where bytes need to be interpreted as text or numbers.
Modifier and Type | Method and Description |
---|---|
long |
addressForRead(long offset)
Retrieves the underlying memory address for reading.
|
default long |
addressForRead(long offset,
int buffer)
Retrieves the underlying memory address for reading.
|
long |
addressForWrite(long offset)
Retrieves the underlying memory address for writing.
|
long |
addressForWritePosition()
Retrieves the underlying memory address for writing at the current write position.
|
default ByteOrder |
byteOrder()
Retrieves the byte order used by the buffer.
|
@NotNull Bytes<?> |
bytesForRead()
Retrieves a Bytes object for reading.
|
@NotNull Bytes<?> |
bytesForWrite()
Retrieves a Bytes object for writing.
|
default long |
capacity() |
boolean |
isDirectMemory()
Checks if the buffer uses direct memory.
|
int |
lastDecimalPlaces()
Returns the number of decimal places in the last parsed floating-point number
(from the
parseDouble() or parseLongDecimal() methods). |
void |
lastDecimalPlaces(int lastDecimalPlaces)
Sets the number of decimal places in the last parsed number.
|
boolean |
lastNumberHadDigits()
Returns whether the last parsed number had any digits.
|
void |
lastNumberHadDigits(boolean lastNumberHadDigits)
Sets whether the last parsed number had any digits.
|
default long |
lengthWritten(long startPosition)
Calculates the length of data written from the given start position.
|
default void |
parse8bit(Appendable buffer,
@NotNull StopCharsTester stopCharsTester)
Parses an ISO-8859-1 encoded string from the byte string until the provided
stopCharsTester
detects an end condition. |
default void |
parse8bit(Appendable buffer,
@NotNull StopCharTester stopCharTester)
Parses an ISO-8859-1 encoded string from the byte string until the provided
stopCharTester
detects an end condition. |
default void |
parse8bit(Bytes<?> buffer,
@NotNull StopCharsTester stopCharsTester)
Parses an ISO-8859-1 encoded string from the byte string until the provided
stopCharsTester
detects an end condition. |
default String |
parse8bit(@NotNull StopCharTester stopCharTester)
Parses an ISO-8859-1 encoded string from the byte string until the provided
stopCharTester
detects an end condition. |
default void |
parse8bit(StringBuilder buffer,
@NotNull StopCharsTester stopCharsTester)
Parses an ISO-8859-1 encoded string from the byte string until the provided
stopCharsTester
detects an end condition. |
default @NotNull BigDecimal |
parseBigDecimal()
Parses text from the byte string as a BigDecimal.
|
default @Nullable Boolean |
parseBoolean()
Attempts to parse the next series of characters in the byte string as a boolean value.
|
default @Nullable Boolean |
parseBoolean(@NotNull StopCharTester tester)
Attempts to parse the next series of characters in the byte string as a boolean value.
|
default double |
parseDouble()
Parses text from the byte string as a double-precision floating-point number.
|
default long |
parseFlexibleLong()
Parses a long integer from the byte string in either standard or scientific notation.
|
default float |
parseFloat()
Parses text from the byte string as a floating-point number.
|
default int |
parseInt()
Parses text from the byte string as an integer.
|
default long |
parseLong()
Parses text from the byte string as a long integer.
|
default long |
parseLongDecimal()
Parses the significant digits of a decimal number from the byte string.
|
default void |
parseUtf8(@NotNull Appendable buffer,
@NotNull StopCharsTester stopCharsTester)
Parses a UTF-8 encoded string from the byte string until the provided
stopCharsTester
detects an end condition. |
default void |
parseUtf8(@NotNull Appendable buffer,
@NotNull StopCharTester stopCharTester)
Parses a UTF-8 encoded string from the byte string until the provided
stopCharTester
detects an end condition. |
default @NotNull String |
parseUtf8(@NotNull StopCharTester stopCharTester)
Parses a UTF-8 encoded string from the byte string until the provided
stopCharTester
detects an end condition. |
default @NotNull Reader |
reader()
Creates a new
Reader from the byte string, assuming the byte string is
ISO-8859-1 encoded. |
default long |
readLimit()
If the resource is closed, the returned value is unspecified.
|
default long |
readPosition()
Returns the read position.
|
default long |
readRemaining()
Calculates the number of bytes remaining that can be read from the current read position.
|
default long |
realCapacity() |
default long |
realReadRemaining()
Calculates the number of bytes that can be safely read directly.
|
default long |
realWriteRemaining()
Calculates the number of bytes remaining that can be written from the current write position with resizing.
|
boolean |
sharedMemory()
Checks if the Bytes use shared memory.
|
default boolean |
skipTo(@NotNull StopCharTester tester)
Skips over characters in the byte string until a terminating character is encountered.
|
default long |
start() |
default long |
writeLimit()
Retrieves the maximum writable position within the buffer.
|
default long |
writePosition()
Returns the write position.
|
default long |
writeRemaining()
Calculates the number of bytes remaining that can be written from the current write position.
|
copyTo, copyTo, inputStream, lenient, lenient, parseHexLong, parseUtf8, parseUtf8, peekUnsignedByte, rawReadByte, rawReadInt, rawReadLong, read, read, read, read, read, read, read8bit, read8bit, read8bit, readBigDecimal, readBigInteger, readBoolean, readByte, readChar, readDouble, readEnum, readFloat, readHistogram, readIncompleteLong, readInt, readInt24, readLimit, readLimitToCapacity, readLong, readPosition, readPositionForHeader, readPositionRemaining, readPositionUnlimited, readShort, readSkip, readStopBit, readStopBitChar, readStopBitDecimal, readStopBitDouble, readUnsignedByte, readUnsignedInt, readUnsignedInt24, readUnsignedShort, readUtf8, readUtf8, readUtf8, readUtf8, readVolatileInt, readVolatileLong, readWithLength, readWithLength, readWithLength0, uncheckedReadSkipBackOne, uncheckedReadSkipOne, uncheckedReadUnsignedByte, unsafeRead, unsafeReadObject, unsafeReadObject
clear
@NotNull default @NotNull Reader reader()
Reader
from the byte string, assuming the byte string is
ISO-8859-1 encoded.Reader
instance that can be used to read the bytes as characters.@Nullable default @Nullable Boolean parseBoolean(@NotNull @NotNull StopCharTester tester) throws BufferUnderflowException, ArithmeticException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
tester
to detect the end of the text. The parsing is case-insensitive.
False can be: "f", "false", "n", "no", "0". True can be: "t", "true", "y", "yes", "1".
tester
- a StopCharTester
used to detect the end of the boolean text.Boolean
value if the text could be parsed as boolean; null otherwise.BufferUnderflowException
- If there is insufficient data.ArithmeticException
- If a numeric overflow occurs.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 way.@Nullable default @Nullable Boolean parseBoolean() throws BufferUnderflowException, ArithmeticException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
StopCharTester
to detect non-alpha-numeric characters.
False can be: "f", "false", "n", "no", "0". True can be: "t", "true", "y", "yes", "1".
Boolean
value if the text could be parsed as boolean; null otherwise.BufferUnderflowException
- If there is insufficient data.ArithmeticException
- If a numeric overflow occurs.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 way.@NotNull default @NotNull String parseUtf8(@NotNull @NotNull StopCharTester stopCharTester) throws ArithmeticException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
stopCharTester
detects an end condition.stopCharTester
- a StopCharTester
used to detect the end of the string.String
.ArithmeticException
- If a numeric overflow occurs.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 way.default void parseUtf8(@NotNull @NotNull Appendable buffer, @NotNull @NotNull StopCharTester stopCharTester) throws BufferUnderflowException, ArithmeticException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
stopCharTester
detects an end condition. The parsed string is appended to the provided buffer
.buffer
- the Appendable
to append the parsed string to.stopCharTester
- a StopCharTester
used to detect the end of the string.BufferUnderflowException
- If there is insufficient data.ArithmeticException
- If a numeric overflow occurs.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 way.default void parseUtf8(@NotNull @NotNull Appendable buffer, @NotNull @NotNull StopCharsTester stopCharsTester) throws BufferUnderflowException, net.openhft.chronicle.core.io.IORuntimeException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
stopCharsTester
detects an end condition. The parsed string is appended to the provided buffer
.buffer
- the Appendable
to append the parsed string to.stopCharsTester
- a StopCharsTester
used to detect the end of the string.BufferUnderflowException
- If there is insufficient data.net.openhft.chronicle.core.io.IORuntimeException
- If an I/O error occurs.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 way.default void parse8bit(Appendable buffer, @NotNull @NotNull StopCharTester stopCharTester) throws BufferUnderflowException, BufferOverflowException, ArithmeticException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
stopCharTester
detects an end condition. The parsed string is appended to the provided buffer
.buffer
- the Appendable
to append the parsed string to.stopCharTester
- a StopCharTester
used to detect the end of the string.BufferUnderflowException
- If there is insufficient data.BufferOverflowException
- If the buffer's capacity was exceeded.ArithmeticException
- If a numeric overflow occurs.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 way.default String parse8bit(@NotNull @NotNull StopCharTester stopCharTester) throws BufferUnderflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
stopCharTester
detects an end condition.stopCharTester
- a StopCharTester
used to detect the end of the string.String
.BufferUnderflowException
- If there is insufficient data.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 way.default void parse8bit(Appendable buffer, @NotNull @NotNull StopCharsTester stopCharsTester) throws BufferUnderflowException, BufferOverflowException, ArithmeticException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
stopCharsTester
detects an end condition. The parsed string is appended to the provided buffer
.buffer
- the Appendable
to append the parsed string to.stopCharsTester
- a StopCharsTester
used to detect the end of the string.BufferUnderflowException
- If there is insufficient data.BufferOverflowException
- If the buffer's capacity was exceeded.ArithmeticException
- If a numeric overflow occurs.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 way.default void parse8bit(Bytes<?> buffer, @NotNull @NotNull StopCharsTester stopCharsTester) throws BufferUnderflowException, BufferOverflowException, ArithmeticException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
stopCharsTester
detects an end condition. The parsed string is appended to the provided buffer
.buffer
- the Bytes
object to append the parsed string to.stopCharsTester
- a StopCharsTester
used to detect the end of the string.BufferUnderflowException
- If there is insufficient data.BufferOverflowException
- If the buffer's capacity was exceeded.ArithmeticException
- If a numeric overflow occurs.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 way.default void parse8bit(StringBuilder buffer, @NotNull @NotNull StopCharsTester stopCharsTester) throws net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
stopCharsTester
detects an end condition. The parsed string is appended to the provided buffer
.buffer
- the StringBuilder
to append the parsed string to.stopCharsTester
- a StopCharsTester
used to detect the end of the string.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 way.default int parseInt() throws BufferUnderflowException, ArithmeticException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
BufferUnderflowException
- If there is insufficient data.ArithmeticException
- If a numeric overflow occurs.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 way.default long parseLong() throws BufferUnderflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
BufferUnderflowException
- If there is insufficient data.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 way.default long parseFlexibleLong() throws BufferUnderflowException, net.openhft.chronicle.core.io.IORuntimeException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
parseDouble()
to long).net.openhft.chronicle.core.io.IORuntimeException
- If the parsed value corresponds to a fractional number or to a number outside the long's range.BufferUnderflowException
- If there is insufficient data.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 way.default float parseFloat() throws BufferUnderflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
lastDecimalPlaces()
.BufferUnderflowException
- If there is insufficient data.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 way.default double parseDouble() throws BufferUnderflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
lastDecimalPlaces()
.BufferUnderflowException
- If there is insufficient data.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 way.default long parseLongDecimal() throws BufferUnderflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
lastDecimalPlaces()
.BufferUnderflowException
- If there is insufficient data.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 way.int lastDecimalPlaces()
parseDouble()
or parseLongDecimal()
methods).void lastDecimalPlaces(int lastDecimalPlaces)
lastDecimalPlaces
- the number of decimal places to set, if positive; otherwise 0.boolean lastNumberHadDigits()
void lastNumberHadDigits(boolean lastNumberHadDigits)
lastNumberHadDigits
- the new value to set, true if the last parsed number had digits, false otherwise.default boolean skipTo(@NotNull @NotNull StopCharTester tester) throws net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
tester
- the StopCharTester instance to use for determining the terminating character.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 way.@NotNull default @NotNull BigDecimal parseBigDecimal() throws ArithmeticException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
ArithmeticException
- If a numerical overflow occurs during the operation.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 way.default long start()
default long capacity()
default long realCapacity()
default long readPosition()
The read position is start() <= readPosition() && readPosition() <= readLimit() && readPosition < safeLimit()
If the resource is closed, the returned value is unspecified.
default long writePosition()
The write position is readPosition() <= writePosition() && writePosition() <= writeLimit()
If the resource is closed, the returned value is unspecified.
default long lengthWritten(long startPosition)
Typically this calculates the difference however for HexDumpBytes it's not as simple.
If the resource is closed, the returned value is unspecified.
startPosition
- The position to calculate the length from.default long readRemaining()
If the resource is closed, the returned value is unspecified.
default long realReadRemaining()
If the resource is closed, the returned value is unspecified.
default long writeRemaining()
If the resource is closed, the returned value is unspecified.
default long realWriteRemaining()
If the resource is closed, the returned value is unspecified.
default long readLimit()
If the resource is closed, the returned value is unspecified.
default long writeLimit()
If the resource is closed, the returned value is unspecified.
long addressForRead(long offset) throws UnsupportedOperationException, BufferUnderflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
offset
- within this buffer. addressForRead(start()) is the actual addressForRead of the first byte.UnsupportedOperationException
- If the underlying buffer is on the heapBufferUnderflowException
- If the offset is before the start() or the after the capacity()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 waydefault long addressForRead(long offset, int buffer) throws UnsupportedOperationException, BufferUnderflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
offset
- The offset within this buffer.buffer
- The buffer index.UnsupportedOperationException
- If the underlying buffer is on the heap.BufferUnderflowException
- If the offset is before the start or after the capacity.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 waylong addressForWrite(long offset) throws UnsupportedOperationException, BufferOverflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
offset
- within this buffer. addressForRead(start()) is the actual addressForRead of the first byte.UnsupportedOperationException
- If the underlying buffer is on the heapBufferOverflowException
- If the offset is before the start() or the after the capacity()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 waylong addressForWritePosition() throws UnsupportedOperationException, BufferOverflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException
UnsupportedOperationException
- If the underlying buffer is on the heap.BufferOverflowException
- If the current write position is before the start or after the capacity.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 waydefault ByteOrder byteOrder()
@NotNull @NotNull Bytes<?> bytesForRead() throws net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
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 way@NotNull @NotNull Bytes<?> bytesForWrite() throws net.openhft.chronicle.core.io.ClosedIllegalStateException
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 wayboolean sharedMemory()
boolean isDirectMemory()
Copyright © 2024. All rights reserved.