public class PrefixedStringDecoder extends CumulativeProtocolDecoder
ProtocolDecoder
which decodes 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 |
---|
PrefixedStringDecoder(Charset charset)
Creates a new PrefixedStringDecoder instance
|
PrefixedStringDecoder(Charset charset,
int prefixLength)
Creates a new PrefixedStringDecoder instance
|
PrefixedStringDecoder(Charset charset,
int prefixLength,
int maxDataLength)
Creates a new PrefixedStringDecoder instance
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
doDecode(IoSession session,
IoBuffer in,
ProtocolDecoderOutput out)
Implement this method to consume the specified cumulative buffer and
decode its content into message(s).
|
int |
getMaxDataLength()
Gets the maximum number of bytes allowed for a single String
|
int |
getPrefixLength()
Gets the length of the length prefix (1, 2, or 4)
|
void |
setMaxDataLength(int maxDataLength)
Sets the maximum allowed value specified as data length in the incoming data
Useful for preventing an OutOfMemory attack by the peer.
|
void |
setPrefixLength(int prefixLength)
Sets the number of bytes used by the length prefix
|
decode, dispose, setTransportMetadataFragmentation
finishDecode
public static final int DEFAULT_PREFIX_LENGTH
public static final int DEFAULT_MAX_DATA_LENGTH
public PrefixedStringDecoder(Charset charset, int prefixLength, int maxDataLength)
charset
- the Charset
to use for decodingprefixLength
- the length of the prefixmaxDataLength
- maximum number of bytes allowed for a single Stringpublic PrefixedStringDecoder(Charset charset, int prefixLength)
charset
- the Charset
to use for decodingprefixLength
- the length of the prefixpublic void setPrefixLength(int prefixLength)
prefixLength
- the length of the length prefix (1, 2, or 4)public int getPrefixLength()
public void setMaxDataLength(int maxDataLength)
Useful for preventing an OutOfMemory attack by the peer.
The decoder will throw a BufferDataException
when data length
specified in the incoming data is greater than maxDataLength
The default value is DEFAULT_MAX_DATA_LENGTH
.
maxDataLength
- maximum allowed value specified as data length in the incoming datapublic int getMaxDataLength()
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception
doDecode
in class CumulativeProtocolDecoder
session
- The current Sessionin
- the cumulative bufferout
- The ProtocolDecoderOutput
that will receive the decoded messageException
- if cannot decode in.Copyright © 2004–2021 Apache MINA Project. All rights reserved.