public abstract class WebSocketMessageReader extends Object
WebSocketMessageReader
is used to receive binary and text messages.
A reference to WebSocketMessageReader
can be obtained by using
WebSocket.getMessageReader()
or
WsURLConnection.getMessageReader()
methods only after a
connection has been successfully established. WebSocketMessageReader
allows looking at WebSocketMessageType
to figure out whether it's a
text or a binary message so that appropriate getter methods can be
subsequently invoked to retrieve the message.
Trying to get a reference to WebSocketMessageReader
before the
connection is established will result in an IOException.
Once the connection is closed, a new WebSocketMessageReader
should
be obtained using the aforementioned methods after the connection has been
established. Using the old reader will result in IOException.
Constructor and Description |
---|
WebSocketMessageReader() |
Modifier and Type | Method and Description |
---|---|
abstract ByteBuffer |
getBinary()
Returns the payload of the last received message.
|
abstract CharSequence |
getText()
Returns the payload of the last received message.
|
abstract WebSocketMessageType |
getType()
Returns the
WebSocketMessageType of the already received message. |
abstract WebSocketMessageType |
next()
Invoking this method will cause the thread to block until a message is
received.
|
public abstract ByteBuffer getBinary() throws IOException
next()
only if the type of the received
message is WebSocketMessageType.BINARY
. This is not a blocking
call.
A null is returned if this method is invoked before invoking
next()
method.
If the type of the last received message is not
WebSocketMessageType.BINARY
, then invoking this method to obtain
the payload of the message as ByteBuffer will result in an IOException.
IOException
- if the type of the last received message is not
WebSocketMessageType.BINARY
public abstract CharSequence getText() throws IOException
next()
only if the type of the received
message is WebSocketMessageType.TEXT
. This is not a blocking
call.
A null is returned if this method is invoked before invoking
next()
method.
If the type of the last received message is not
WebSocketMessageType.TEXT
, then invoking this method to obtain
the payload of the message as CharSequence will result in an IOException.
IOException
- if the type of the last received message is not
WebSocketMessageType.TEXT
public abstract WebSocketMessageType getType()
WebSocketMessageType
of the already received message.
This method returns a null until the first message is received. Note
that this is not a blocking call. When connected, if this method is
invoked immediately after next()
, then they will return the same
value.
Based on the returned WebSocketMessageType
, appropriate read
methods can be used to receive the message. This method will continue to
return the same WebSocketMessageType
till the next message
arrives. When the next message arrives, this method will return the
the WebSocketMessageType
associated with that message.
public abstract WebSocketMessageType next() throws IOException
WebSocketMessageType
, appropriate getter methods can be used to
retrieve the binary or text message. When the connection is closed, this
method returns WebSocketMessageType.EOS
.
An IOException is thrown if this method is invoked before the connection has been established.
IOException
- if invoked before the connection is establishedCopyright © 2014. All Rights Reserved.