Package com.google.genai.gaos.utils
Class StreamingParser<T>
java.lang.Object
com.google.genai.gaos.utils.StreamingParser<T>
Generic streaming parser that handles byte buffer management and delegates
format-specific logic to a StreamContentProcessor.
-
Method Summary
Modifier and TypeMethodDescriptionadd(ByteBuffer inputBuffer) Add ByteBuffer data to the parser buffer and extract any complete items.finish()Extract any remaining partial content when stream ends.static StreamingParser<String>Create a streaming parser for JSON Lines formatstatic StreamingParser<EventStreamMessage>forSSE()Create a streaming parser for SSE formatbooleanCheck if parser has any buffered datastatic booleanmatchesPattern(byte[] data, int pos, int limit, byte... pattern) Check if a byte pattern matches at a specific positionnext()Check if there are additional complete items in the buffer.
-
Method Details
-
add
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
Extract any remaining partial content when stream ends.- Returns:
- final parsed result if there was incomplete data in the buffer
-
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
Create a streaming parser for JSON Lines format -
forSSE
Create a streaming parser for SSE format
-