public class PrefixedStringEncoder extends ProtocolEncoderAdapter
ProtocolEncoder
which encodes a string
using a fixed-length length prefix.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_DATA_LENGTH
The default maximum data length
|
static int |
DEFAULT_PREFIX_LENGTH
The default length for the prefix
|
Constructor and Description |
---|
PrefixedStringEncoder()
Creates a new PrefixedStringEncoder instance
|
PrefixedStringEncoder(Charset charset)
Creates a new PrefixedStringEncoder instance
|
PrefixedStringEncoder(Charset charset,
int prefixLength)
Creates a new PrefixedStringEncoder instance
|
PrefixedStringEncoder(Charset charset,
int prefixLength,
int maxDataLength)
Creates a new PrefixedStringEncoder instance
|
Modifier and Type | Method and Description |
---|---|
void |
encode(IoSession session,
Object message,
ProtocolEncoderOutput out)
Encodes higher-level message objects into binary or protocol-specific data.
|
int |
getMaxDataLength()
Gets the maximum number of bytes allowed for encoding a single String *
|
int |
getPrefixLength()
Gets the length of the length prefix (1, 2, or 4)
|
void |
setMaxDataLength(int maxDataLength)
Sets the maximum number of bytes allowed for encoding a single String
(including the prefix)
The encoder will throw a
IllegalArgumentException when more bytes
are needed to encode a String value. |
void |
setPrefixLength(int prefixLength)
Sets the number of bytes used by the length prefix
|
dispose
public static final int DEFAULT_PREFIX_LENGTH
public static final int DEFAULT_MAX_DATA_LENGTH
public PrefixedStringEncoder(Charset charset, int prefixLength, int maxDataLength)
charset
- the Charset
to use for encodingprefixLength
- the length of the prefixmaxDataLength
- maximum number of bytes allowed for a single Stringpublic PrefixedStringEncoder(Charset charset, int prefixLength)
charset
- the Charset
to use for encodingprefixLength
- the length of the prefixpublic PrefixedStringEncoder(Charset charset)
charset
- the Charset
to use for encodingpublic PrefixedStringEncoder()
public void setPrefixLength(int prefixLength)
prefixLength
- the length of the length prefix (1, 2, or 4)public int getPrefixLength()
public void setMaxDataLength(int maxDataLength)
The encoder will throw a IllegalArgumentException
when more bytes
are needed to encode a String value.
The default value is DEFAULT_MAX_DATA_LENGTH
.
maxDataLength
- maximum number of bytes allowed for encoding a single Stringpublic int getMaxDataLength()
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception
ProtocolEncoder.encode(IoSession, Object, ProtocolEncoderOutput)
method with message which is popped from the session write queue, and then
the encoder implementation puts encoded messages (typically IoBuffer
s)
into ProtocolEncoderOutput
.session
- The current Sessionmessage
- the message to encodeout
- The ProtocolEncoderOutput
that will receive the encoded messageException
- if the message violated protocol specificationCopyright © 2004–2022 Apache MINA Project. All rights reserved.