Package pl.gsmservice.gateway.utils
Class StreamingParser<T>
- java.lang.Object
-
- pl.gsmservice.gateway.utils.StreamingParser<T>
-
public final class StreamingParser<T> extends java.lang.ObjectGeneric streaming parser that handles byte buffer management and delegates format-specific logic to a StreamContentProcessor.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<T>add(java.nio.ByteBuffer inputBuffer)Add ByteBuffer data to the parser buffer and extract any complete items.java.util.Optional<T>finish()Extract any remaining partial content when stream ends.static StreamingParser<java.lang.String>forJsonLines()Create a streaming parser for JSON Lines formatstatic StreamingParser<EventStreamMessage>forSSE()Create a streaming parser for SSE formatbooleanhasBufferedData()Check if parser has any buffered datastatic booleanmatchesPattern(byte[] data, int pos, int limit, byte... pattern)Check if a byte pattern matches at a specific positionjava.util.Optional<T>next()Check if there are additional complete items in the buffer.
-
-
-
Method Detail
-
add
public java.util.Optional<T> add(java.nio.ByteBuffer inputBuffer)
Add ByteBuffer data to the parser buffer and extract any complete items.- Parameters:
inputBuffer- byte data to add (will not be modified)- Returns:
- next complete parsed result if one becomes available
-
finish
public java.util.Optional<T> finish()
Extract any remaining partial content when stream ends.- Returns:
- final parsed result if there was incomplete data in the buffer
-
next
public java.util.Optional<T> next()
Check if there are additional complete items in the buffer.- Returns:
- next complete parsed result from buffer if available
-
hasBufferedData
public boolean hasBufferedData()
Check if parser has any buffered data
-
matchesPattern
public static boolean matchesPattern(byte[] data, int pos, int limit, byte... pattern)Check if a byte pattern matches at a specific position
-
forJsonLines
public static StreamingParser<java.lang.String> forJsonLines()
Create a streaming parser for JSON Lines format
-
forSSE
public static StreamingParser<EventStreamMessage> forSSE()
Create a streaming parser for SSE format
-
-