Class BoundedLineAccumulator
java.lang.Object
org.a2aproject.sdk.client.http.BoundedLineAccumulator
Accumulates raw bytes for a single line while enforcing a configurable byte limit.
Used by both the blocking (readBoundedLine) and reactive
(BoundedLineBodySubscriber) bounded-line readers to centralise the
accumulation logic and limit enforcement.
When maxLineBytes <= 0 the per-line byte cap is disabled.
-
Constructor Summary
ConstructorsConstructorDescriptionBoundedLineAccumulator(int maxLineBytes) Creates a new accumulator with the given per-line byte limit. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddByte(int b) Adds a single byte to the accumulator.voidaddChunk(byte[] chunk, int off, int len) Adds a chunk of bytes to the accumulator.booleanReturnstrueif the accumulated bytes have exceeded the configured limit.voidreset()Resets the accumulator for the next line, clearing all accumulated bytes and the "too long" flag.intsize()Returns the number of bytes currently accumulated.toLine()Assembles the accumulated bytes into a UTF-8 string.
-
Constructor Details
-
BoundedLineAccumulator
public BoundedLineAccumulator(int maxLineBytes) Creates a new accumulator with the given per-line byte limit.- Parameters:
maxLineBytes- the maximum number of bytes per line (0= disabled)
-
-
Method Details
-
addByte
public void addByte(int b) Adds a single byte to the accumulator.If the limit has already been exceeded, the byte is silently discarded. If adding this byte would exceed the limit, the accumulator transitions to the "too long" state and discards all previously accumulated bytes.
- Parameters:
b- the byte to add (only the low 8 bits are used)
-
addChunk
public void addChunk(byte[] chunk, int off, int len) Adds a chunk of bytes to the accumulator.If the accumulated byte count plus the chunk length would exceed the limit, the accumulator transitions to the "too long" state and discards all previously accumulated bytes. The chunk is not written.
- Parameters:
chunk- the byte array to add fromoff- the start offset within the arraylen- the number of bytes to add
-
isTooLong
public boolean isTooLong()Returnstrueif the accumulated bytes have exceeded the configured limit. -
size
public int size()Returns the number of bytes currently accumulated. -
toLine
Assembles the accumulated bytes into a UTF-8 string.- Returns:
- the decoded line
-
reset
public void reset()Resets the accumulator for the next line, clearing all accumulated bytes and the "too long" flag.
-