Top Description Inners Methods
jakarta.websocket

public Interface Decoder

Known Direct Subinterfaces
jakarta.websocket.Decoder.Binary, jakarta.websocket.Decoder.BinaryStream, jakarta.websocket.Decoder.Text, jakarta.websocket.Decoder.TextStream
Imports
java.io.IOException, .InputStream, .Reader, java.nio.ByteBuffer

The Decoder interface holds member interfaces that define how a developer can provide the web socket container a way web socket messages into developer defined custom objects. The websocket implementation creates a new instance of the decoder per endpoint instance per connection. The lifecycle of the Decoder instance is governed by the container calls to the Decoder#init(jakarta.websocket.EndpointConfig) and Decoder#destroy() methods.
Author
dannycoward

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Decoder.Binary<
The type of the object that is decoded
T
>

This interface defines how a custom object (of type T) is decoded from a web socket message in the form of a byte buffer.

public static interface
Decoder.BinaryStream<
The type of the object that is decoded
T
>

This interface defines how a custom object is decoded from a web socket message in the form of a binary stream.

public static interface
Decoder.Text<
The type of the object that is decoded
T
>

This interface defines how a custom object is decoded from a web socket message in the form of a string.

public static interface
Decoder.TextStream<
The type of the object that is decoded
T
>

This interface defines how a custom object of type T is decoded from a web socket message in the form of a character stream.

Method Summary

Modifier and TypeMethod and Description
public default void
destroy()

This method is called when the decoder is about to be removed from service in order that any resources the decoder used may be closed gracefully.

public default void
init(EndpointConfig
the endpoint configuration object when being brought into service
config
)

This method is called with the endpoint configuration object of the endpoint this decoder is intended for when it is about to be brought into service.

Method Detail

destroyback to summary
public default void destroy()

This method is called when the decoder is about to be removed from service in order that any resources the decoder used may be closed gracefully.

Implementation Specification

The default implementation takes no action.

initback to summary
public default void init(EndpointConfig config)

This method is called with the endpoint configuration object of the endpoint this decoder is intended for when it is about to be brought into service.

Implementation Specification

The default implementation takes no action.

Parameters
config:EndpointConfig

the endpoint configuration object when being brought into service

jakarta.websocket back to summary

public Interface Decoder.Binary<T>

extends Decoder
Type Parameters
<T>
The type of the object that is decoded

This interface defines how a custom object (of type T) is decoded from a web socket message in the form of a byte buffer.

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

the decoded object.
decode
(ByteBuffer
the bytes to be decoded.
bytes
)

Decode the given bytes into an object of type T.

public boolean

Returns:

whether or not the bytes can be decoded by this decoder.
willDecode
(ByteBuffer
the bytes to be decoded.
bytes
)

Answer whether the given bytes can be decoded into an object of type T.

Inherited from jakarta.websocket.Decoder:
destroyinit

Method Detail

decodeback to summary
public T decode(ByteBuffer bytes) throws DecodeException

Decode the given bytes into an object of type T.

It is not safe for other threads to use the ByteBuffer until the decoding of the given bytes is complete. If the decoding completes successfully, the buffer's limit will be unchanged and the buffer's position will be equal to the limit. If the decoding does not complete successfully, the state of the buffer is undefined.

Parameters
bytes:ByteBuffer

the bytes to be decoded.

Returns:T

the decoded object.

Exceptions
DecodeException:
If the provided bytes cannot be decoded to type T
willDecodeback to summary
public boolean willDecode(ByteBuffer bytes)

Answer whether the given bytes can be decoded into an object of type T.

It is not safe for other threads to use the ByteBuffer until this method completes. When the method completes, the buffer will be in the same state as it was at the start of the method call.

Parameters
bytes:ByteBuffer

the bytes to be decoded.

Returns:boolean

whether or not the bytes can be decoded by this decoder.

jakarta.websocket back to summary

public Interface Decoder.BinaryStream<T>

extends Decoder
Type Parameters
<T>
The type of the object that is decoded

This interface defines how a custom object is decoded from a web socket message in the form of a binary stream.

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

the decoded object.
decode
(InputStream
the input stream carrying the bytes.
is
)

Decode the given bytes read from the input stream into an object of type T.

Inherited from jakarta.websocket.Decoder:
destroyinit

Method Detail

decodeback to summary
public T decode(InputStream is) throws DecodeException, IOException

Decode the given bytes read from the input stream into an object of type T.

Parameters
is:InputStream

the input stream carrying the bytes.

Returns:T

the decoded object.

Exceptions
DecodeException:
If the provided input stream cannot be decoded to type T
IOException:
If an error occurs reading the input stream
jakarta.websocket back to summary

public Interface Decoder.Text<T>

extends Decoder
Type Parameters
<T>
The type of the object that is decoded

This interface defines how a custom object is decoded from a web socket message in the form of a string.

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

the decoded message as an object of type T
decode
(String
string to be decoded.
s
)

Decode the given String into an object of type T.

public boolean

Returns:

whether this decoder can decoded the supplied string.
willDecode
(String
the string being tested for decodability.
s
)

Answer whether the given String can be decoded into an object of type T.

Inherited from jakarta.websocket.Decoder:
destroyinit

Method Detail

decodeback to summary
public T decode(String s) throws DecodeException

Decode the given String into an object of type T.

Parameters
s:String

string to be decoded.

Returns:T

the decoded message as an object of type T

Exceptions
DecodeException:
If the provided string cannot be decoded to type T
willDecodeback to summary
public boolean willDecode(String s)

Answer whether the given String can be decoded into an object of type T.

Parameters
s:String

the string being tested for decodability.

Returns:boolean

whether this decoder can decoded the supplied string.

jakarta.websocket back to summary

public Interface Decoder.TextStream<T>

extends Decoder
Type Parameters
<T>
The type of the object that is decoded

This interface defines how a custom object of type T is decoded from a web socket message in the form of a character stream.

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

the instance of the object that is the decoded web socket message.
decode
(Reader
the reader from which to read the web socket message.
reader
)

Reads the websocket message from the implementation provided Reader and decodes it into an instance of the supplied object type.

Inherited from jakarta.websocket.Decoder:
destroyinit

Method Detail

decodeback to summary
public T decode(Reader reader) throws DecodeException, IOException

Reads the websocket message from the implementation provided Reader and decodes it into an instance of the supplied object type.

Parameters
reader:Reader

the reader from which to read the web socket message.

Returns:T

the instance of the object that is the decoded web socket message.

Exceptions
DecodeException:
If the data from the provided reader cannot be decoded to type T
IOException:
If an error occurs reading from the reader