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

public Class MessageInputStream

extends InputStream
implements MessageSink
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.websocket.core.messages.MessageSink
Imports
java.io.IOException, .InputStream, .InterruptedIOException, java.nio.ByteBuffer, java.util.ArrayDeque, .ArrayList, java.util.concurrent.TimeUnit, org.eclipse.jetty.util.BufferUtil, .Callback, .IO, org.eclipse.jetty.util.thread.AutoLock, org.eclipse.jetty.websocket.core.CoreSession, .Frame, org.slf4j.Logger, .LoggerFactory

Support class for reading a WebSocket BINARY message via a InputStream.

An InputStream that can access a queue of ByteBuffer payloads, along with expected InputStream blocking behavior.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record

Field Summary

Modifier and TypeField and Description
private final ArrayDeque<MessageInputStream.Entry>
private static final MessageInputStream.Entry
private boolean
private MessageInputStream.Entry
private static final MessageInputStream.Entry
private static final MessageInputStream.Entry
private Throwable
private final AutoLock.WithCondition
private static final Logger
private final CoreSession
private long

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()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

private void
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.

private MessageInputStream.Entry
private Throwable
public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

public int
read(ByteBuffer buffer)

public void
setTimeout(long timeoutMs)

private void
Inherited from java.io.InputStream:
availablemarkmarkSupportednullInputStreamreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

buffersback to summary
private final ArrayDeque<MessageInputStream.Entry> buffers
CLOSEDback to summary
private static final MessageInputStream.Entry CLOSED
closedback to summary
private boolean closed
currentEntryback to summary
private MessageInputStream.Entry currentEntry
EOFback to summary
private static final MessageInputStream.Entry EOF
FAILEDback to summary
private static final MessageInputStream.Entry FAILED
failureback to summary
private Throwable failure
lockback to summary
private final AutoLock.WithCondition lock
LOGback to summary
private static final Logger LOG
sessionback to summary
private final CoreSession session
timeoutMsback to summary
private long timeoutMs

Constructor Detail

MessageInputStreamback to summary
public MessageInputStream(CoreSession session)

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()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Annotations
@Override
drainIntoback to summary
private void drainInto(ArrayList<MessageInputStream.Entry> entries)
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
getCurrentEntryback to summary
private MessageInputStream.Entry getCurrentEntry() throws IOException
getFailureback to summary
private Throwable getFailure()
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
readback to summary
public int read(ByteBuffer buffer) throws IOException
setTimeoutback to summary
public void setTimeout(long timeoutMs)
succeedCurrentEntryback to summary
private void succeedCurrentEntry()
org.eclipse.jetty.websocket.core.messages back to summary

private final Record MessageInputStream.Entry

extends Record
Class Inheritance
Record Components
frame:Frame 
callback:Callback 

Field Summary

Modifier and TypeField and Description
private final Callback
callback

Record Component accessed by callback().

private final Frame
frame

Record Component accessed by frame().

Constructor Summary

AccessConstructor and Description
private
Entry(Frame frame, Callback callback)

Method Summary

Modifier and TypeMethod and Description
public Callback
callback()

Record Component getter of callback.

public final boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public Frame
frame()

Record Component getter of frame.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

callbackback to summary
private final Callback callback

Record Component accessed by callback().

frameback to summary
private final Frame frame

Record Component accessed by frame().

Constructor Detail

Entryback to summary
private Entry(Frame frame, Callback callback)

Method Detail

callbackback to summary
public Callback callback()

Record Component getter of callback.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

frameback to summary
public Frame frame()

Record Component getter of frame.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Returns:String

a string representation of the object.