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 |
static int |
DEFAULT_PREFIX_LENGTH |
Constructor and Description |
---|
PrefixedStringEncoder() |
PrefixedStringEncoder(java.nio.charset.Charset charset) |
PrefixedStringEncoder(java.nio.charset.Charset charset,
int prefixLength) |
PrefixedStringEncoder(java.nio.charset.Charset charset,
int prefixLength,
int maxDataLength) |
Modifier and Type | Method and Description |
---|---|
void |
encode(IoSession session,
java.lang.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(java.nio.charset.Charset charset, int prefixLength, int maxDataLength)
public PrefixedStringEncoder(java.nio.charset.Charset charset, int prefixLength)
public PrefixedStringEncoder(java.nio.charset.Charset charset)
public 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, java.lang.Object message, ProtocolEncoderOutput out) throws java.lang.Exception
ProtocolEncoder
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
.java.lang.Exception
- if the message violated protocol specificationCopyright © 2004-2019 Apache MINA Project. All Rights Reserved.