Top Description Fields Constructors Methods
org.eclipse.jetty.websocket.core.messages

public Class MessageReader

extends Reader
implements MessageSink
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.websocket.core.messages.MessageSink
Imports
java.io.IOException, .Reader, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.CharsetDecoder, .CoderResult, .CodingErrorAction, .StandardCharsets, org.eclipse.jetty.util.BufferUtil, .Callback, org.eclipse.jetty.websocket.core.CoreSession, .Frame

Support class for reading a (single) WebSocket TEXT message via a Reader.

In compliance to the WebSocket spec, this reader always uses the StandardCharsets#UTF_8.

Field Summary

Modifier and TypeField and Description
private final ByteBuffer
private final MessageInputStream
private final CharsetDecoder
Inherited from java.io.Reader:
lock

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
accept(Frame
the frame to consume
frame
,
Callback
the callback to complete when the frame is consumed
callback
)

Implements org.eclipse.jetty.websocket.core.messages.MessageSink.accept.

Consumes the WebSocket frame, possibly asynchronously when this method has returned.

public void
close()

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes the stream and releases any system resources associated with it.

public void
fail(Throwable
the cause of the failure
failure
)

Overrides default org.eclipse.jetty.websocket.core.messages.MessageSink.fail.

Fails this MessageSink with the given cause.

public int
read(char[]
Destination buffer
chars
,
int
Offset at which to start storing characters
off
,
int
Maximum number of characters to read
len
)

Implements abstract java.io.Reader.read.

Reads characters into a portion of an array.

Inherited from java.io.Reader:
markmarkSupportednullReaderofreadreadreadreadAllAsStringreadAllLinesreadyresetskiptransferTo

Field Detail

bufferback to summary
private final ByteBuffer buffer
streamback to summary
private final MessageInputStream stream
utf8Decoderback to summary
private final CharsetDecoder utf8Decoder

Constructor Detail

MessageReaderback to summary
public MessageReader(CoreSession coreSession)

Method Detail

acceptback to summary
public void accept(Frame frame, Callback callback)

Implements org.eclipse.jetty.websocket.core.messages.MessageSink.accept.

Doc from org.eclipse.jetty.websocket.core.messages.MessageSink.accept.

Consumes the WebSocket frame, possibly asynchronously when this method has returned.

The callback argument must be completed when the frame payload is consumed.

The demand for more frames must be explicitly invoked, or arranged to be invoked asynchronously, by the implementation of this method, by calling CoreSession#demand().

Parameters
frame:Frame

the frame to consume

callback:Callback

the callback to complete when the frame is consumed

Annotations
@Override
closeback to summary
public void close() throws IOException

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Doc from java.io.Reader.close.

Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
failback to summary
public void fail(Throwable failure)

Overrides default org.eclipse.jetty.websocket.core.messages.MessageSink.fail.

Doc from org.eclipse.jetty.websocket.core.messages.MessageSink.fail.

Fails this MessageSink with the given cause.

Parameters
failure:Throwable

the cause of the failure

Annotations
@Override
readback to summary
public int read(char[] chars, int off, int len) throws IOException

Implements abstract java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If len is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Parameters
chars:char[]

Destination buffer

off:int

Offset at which to start storing characters

len:int

Maximum number of characters to read

Returns:int

The number of characters read, or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs