Top Description Inners Methods
jakarta.websocket

public Interface Encoder

Known Direct Subinterfaces
jakarta.websocket.Encoder.Text, jakarta.websocket.Encoder.TextStream, jakarta.websocket.Encoder.Binary, jakarta.websocket.Encoder.BinaryStream
Imports
java.io.IOException, .OutputStream, .Writer, java.nio.ByteBuffer

The Encoder interface defines how developers can provide a way to convert their custom objects into web socket messages. The Encoder interface contains subinterfaces that allow encoding algorithms to encode custom objects to: text, binary data, character stream and write to an output stream. The websocket implementation creates a new instance of the encoder per endpoint instance per connection. This means that each encoder instance has at most one calling thread at a time. The lifecycle of the Encoder instance is governed by the container calls to the Encoder#init(jakarta.websocket.EndpointConfig) and Encoder#destroy() methods.
Author
dannycoward

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Encoder.Binary<
The type of the custom object that this Encoder can encoder to a ByteBuffer.
T
>

This interface defines how to provide a way to convert a custom object into a binary message.

public static interface
Encoder.BinaryStream<
the type of the object this encoder can encode.
T
>

This interface may be implemented by encoding algorithms that want to write the encoded object to a binary stream.

public static interface
Encoder.Text<
The type of the custom developer object that this Encoder can encode into a String.
T
>

This interface defines how to provide a way to convert a custom object into a text message.

public static interface
Encoder.TextStream<
the type of the object this encoder can encode to a CharacterStream.
T
>

This interface may be implemented by encoding algorithms that want to write the encoded object to a character stream.

Method Summary

Modifier and TypeMethod and Description
public default void
destroy()

This method is called when the encoder is about to be removed from service in order that any resources the encoder 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 encoder 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 encoder is about to be removed from service in order that any resources the encoder 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 encoder 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 Encoder.Binary<T>

extends Encoder
Type Parameters
<T>
The type of the custom object that this Encoder can encoder to a ByteBuffer.

This interface defines how to provide a way to convert a custom object into a binary message.

Method Summary

Modifier and TypeMethod and Description
public ByteBuffer

Returns:

the binary data.
encode
(T
the object being encoded.
object
)

Encode the given object into a byte array.

Inherited from jakarta.websocket.Encoder:
destroyinit

Method Detail

encodeback to summary
public ByteBuffer encode(T object) throws EncodeException

Encode the given object into a byte array.

Parameters
object:T

the object being encoded.

Returns:ByteBuffer

the binary data.

Exceptions
EncodeException:
The provided object could not be encoded to a byte buffer
jakarta.websocket back to summary

public Interface Encoder.BinaryStream<T>

extends Encoder
Type Parameters
<T>
the type of the object this encoder can encode.

This interface may be implemented by encoding algorithms that want to write the encoded object to a binary stream.

Method Summary

Modifier and TypeMethod and Description
public void
encode(T
the object being encoded.
object
,
OutputStream
the output stream where the encoded data is written.
os
)

Encode the given object into a binary stream written to the implementation provided OutputStream.

Inherited from jakarta.websocket.Encoder:
destroyinit

Method Detail

encodeback to summary
public void encode(T object, OutputStream os) throws EncodeException, IOException

Encode the given object into a binary stream written to the implementation provided OutputStream.

Parameters
object:T

the object being encoded.

os:OutputStream

the output stream where the encoded data is written.

Exceptions
EncodeException:
The provided object could not be encoded to an output stream
IOException:
If an error occurred writing to the output stream
jakarta.websocket back to summary

public Interface Encoder.Text<T>

extends Encoder
Type Parameters
<T>
The type of the custom developer object that this Encoder can encode into a String.

This interface defines how to provide a way to convert a custom object into a text message.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the encoded object as a string.
encode
(T
the object being encoded.
object
)

Encode the given object into a String.

Inherited from jakarta.websocket.Encoder:
destroyinit

Method Detail

encodeback to summary
public String encode(T object) throws EncodeException

Encode the given object into a String.

Parameters
object:T

the object being encoded.

Returns:String

the encoded object as a string.

Exceptions
EncodeException:
The provided object could not be encoded as a string
jakarta.websocket back to summary

public Interface Encoder.TextStream<T>

extends Encoder
Type Parameters
<T>
the type of the object this encoder can encode to a CharacterStream.

This interface may be implemented by encoding algorithms that want to write the encoded object to a character stream.

Method Summary

Modifier and TypeMethod and Description
public void
encode(T
the object to be encoded.
object
,
Writer
the writer provided by the web socket runtime to write the encoded data.
writer
)

Encode the given object to a character stream writing it to the supplied Writer.

Inherited from jakarta.websocket.Encoder:
destroyinit

Method Detail

encodeback to summary
public void encode(T object, Writer writer) throws EncodeException, IOException

Encode the given object to a character stream writing it to the supplied Writer. Implementations of this method may use the EncodeException to indicate a failure to convert the supplied object to an encoded form, and may use the IOException to indicate a failure to write the data to the supplied stream.

Parameters
object:T

the object to be encoded.

writer:Writer

the writer provided by the web socket runtime to write the encoded data.

Exceptions
EncodeException:
if there was an error encoding the object due to its state.
IOException:
if there was an exception writing to the writer.