Package org.apache.juneau.marshall.sse
Class SseEventReader
java.lang.Object
org.apache.juneau.marshall.sse.SseEventReader
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterator<SseEvent>
Line-driven text/event-stream .
Iterator over the events in a
Wraps a Reader the caller owns and dispatches one SseEvent at a time using the
WHATWG parse state machine (HTML ยง9.2).
Designed for long-lived SSE streams that outlive any reasonable per-call buffer.
Why a separate class:
No other Juneau marshaller ships a separate iterator-style helper. SSE warrants the deviation
because SSE responses are open until the client disconnects or the server pushes its last event;
forcing callers through the eager List<SseEvent> path would defeat the entire point of
using SSE.
Example:
Notes:
- This class is not thread safe.
See Also:
-
Constructor Details
-
SseEventReader
Constructor.- Parameters:
in- The reader to consume events from. Must not benull . Caller retains ownership;close()closes this reader.
-
-
Method Details
-
hasNext
-
next
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
toList
Drains the remaining events into a list, then closes this reader.- Returns:
- The list of events in order.
- Throws:
IOException- If an I/O error occurs while reading.
-