public final class ServerSentEventReader
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
ServerSentEventReader.Callback |
Modifier and Type | Field and Description |
---|---|
private ServerSentEventReader.Callback |
callback |
private static okio.ByteString |
CRLF |
private static okio.ByteString |
DATA |
private static okio.ByteString |
EVENT |
private static okio.ByteString |
ID |
private java.lang.String |
lastId |
private static okio.ByteString |
RETRY |
private okio.BufferedSource |
source |
Constructor and Description |
---|
ServerSentEventReader(okio.BufferedSource source,
ServerSentEventReader.Callback callback) |
Modifier and Type | Method and Description |
---|---|
private void |
completeEvent(java.lang.String id,
java.lang.String type,
okio.Buffer data) |
private boolean |
isKey(okio.ByteString key)
Returns true if the first bytes of
source are key followed by a colon or
a newline. |
private void |
parseData(okio.Buffer data,
long end) |
private java.lang.String |
parseEvent(long end) |
private java.lang.String |
parseId(long end) |
private void |
parseRetry(long end) |
(package private) boolean |
processNextEvent()
Process the next event.
|
private void |
skipCrAndOrLf()
|
private long |
skipNameAndDivider(long length)
Consumes the field name of the specified length and the optional colon and its optional
trailing space.
|
private static final okio.ByteString CRLF
private static final okio.ByteString DATA
private static final okio.ByteString ID
private static final okio.ByteString EVENT
private static final okio.ByteString RETRY
private final okio.BufferedSource source
private final ServerSentEventReader.Callback callback
private java.lang.String lastId
public ServerSentEventReader(okio.BufferedSource source, ServerSentEventReader.Callback callback)
boolean processNextEvent() throws java.io.IOException
ServerSentEventReader.Callback.onEvent(java.lang.String, java.lang.String, java.lang.String)
unless the data section was empty. Any number of calls to
ServerSentEventReader.Callback.onRetryChange(long)
may occur while processing an event.java.io.IOException
private void completeEvent(java.lang.String id, java.lang.String type, okio.Buffer data) throws java.io.IOException
java.io.IOException
private void parseData(okio.Buffer data, long end) throws java.io.IOException
java.io.IOException
private java.lang.String parseEvent(long end) throws java.io.IOException
java.io.IOException
private java.lang.String parseId(long end) throws java.io.IOException
java.io.IOException
private void parseRetry(long end) throws java.io.IOException
java.io.IOException
private boolean isKey(okio.ByteString key) throws java.io.IOException
source
are key
followed by a colon or
a newline.java.io.IOException
private void skipCrAndOrLf() throws java.io.IOException
java.io.IOException
private long skipNameAndDivider(long length) throws java.io.IOException
java.io.IOException