java.lang.Object
io.helidon.common.buffers.DataReader
Data reader that can pull additional data.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classNew line not valid.static classNot enough data available to finish the requested operation. -
Constructor Summary
ConstructorsConstructorDescriptionDataReader(Supplier<byte[]> bytesSupplier) Data reader from a supplier of bytes.DataReader(Supplier<byte[]> bytesSupplier, boolean ignoreLoneEol) Data reader from a supplier of bytes. -
Method Summary
Modifier and TypeMethodDescriptionintNumber of bytes available in the currently pulled data.Debug data as a hex string.voidEnsure we have at least one byte available.intfindNewLine(int max) Find new line with the next n bytes.intfindOrNewLine(byte b, int max) Find the byte or next new line.getBuffer(int length) Get the next buffer of the requested size without moving position.<T> voidlistener(DataListener<T> listener, T context) Configure data listener.bytelookup()Look at the next byte (does not modify position).voidpullData()Pull next data.byteread()Read 1 byte.readAsciiString(int len) Read ascii string.Read next buffer.readBuffer(int length) Read next buffer of defined size.readLazyString(Charset charset, int len) Read the nextlenbytes as aLazyString.readLine()Read an ascii string until new line.voidskip(int lenToSkip) Skip n bytes.booleanstartsWith(byte[] prefix) Does the current data start with the prefix.booleanDoes the data start with a new line (CRLF).
-
Constructor Details
-
DataReader
Data reader from a supplier of bytes.- Parameters:
bytesSupplier- supplier that can be pulled for more data
-
DataReader
Data reader from a supplier of bytes.- Parameters:
bytesSupplier- supplier that can be pulled for more dataignoreLoneEol- ignore LF without CR and CR without LF
-
-
Method Details
-
available
public int available()Number of bytes available in the currently pulled data.- Returns:
- number of bytes available
-
pullData
public void pullData()Pull next data. -
skip
public void skip(int lenToSkip) Skip n bytes.- Parameters:
lenToSkip- number of bytes to skip (must be less or equal to current capacity)
-
ensureAvailable
public void ensureAvailable()Ensure we have at least one byte available. -
read
public byte read()Read 1 byte.- Returns:
- next byte
-
lookup
public byte lookup()Look at the next byte (does not modify position).- Returns:
- next byte
-
startsWithNewLine
public boolean startsWithNewLine()Does the data start with a new line (CRLF).- Returns:
- whether the data starts with a new line (will pull data to have at least two bytes available)
-
startsWith
public boolean startsWith(byte[] prefix) Does the current data start with the prefix.- Parameters:
prefix- prefix to find, will pull data to have at least prefix.length bytes available- Returns:
- whether the data starts with the provided prefix
-
readBuffer
Read next buffer. Will readavailable()number of bytes into a buffer and move position.- Returns:
- buffer data wrapping the available bytes
-
readBuffer
Read next buffer of defined size. Will pull additional data if length is not available. Will move position.- Parameters:
length- length of data to read- Returns:
- buffer data with the length requested
-
getBuffer
Get the next buffer of the requested size without moving position.- Parameters:
length- bytes to read- Returns:
- buffer data with the length requested
-
readLazyString
Read the nextlenbytes as aLazyString. This should be used for example for headers, where we want to materialize the string only when needed.- Parameters:
charset- character set to uselen- number of bytes of the string- Returns:
- lazy string
-
readAsciiString
Read ascii string.- Parameters:
len- number of bytes of the string- Returns:
- string value
-
readLine
Read an ascii string until new line.- Returns:
- string with the next line
- Throws:
DataReader.IncorrectNewLineException- when new line cannot be found
-
findOrNewLine
Find the byte or next new line.- Parameters:
b- - byte to findmax- - search limit- Returns:
- i > 0 - index; i == max - not found; i < 0 - new line found at (-i-1) position
- Throws:
DataReader.IncorrectNewLineException- in case new line was incorrect (such as CR not before LF)
-
debugDataHex
Debug data as a hex string.- Returns:
- hex string, including headers
-
findNewLine
Find new line with the next n bytes.- Parameters:
max- length to search- Returns:
- index of the new line, or max if not found
- Throws:
DataReader.IncorrectNewLineException
-
listener
Configure data listener.- Type Parameters:
T- type of the context- Parameters:
listener- listener to write information tocontext- context
-