Class PrefixedStringEncoder
java.lang.Object
org.apache.mina.filter.codec.ProtocolEncoderAdapter
org.apache.mina.filter.codec.prefixedstring.PrefixedStringEncoder
- All Implemented Interfaces:
ProtocolEncoder
A
ProtocolEncoder which encodes a string
using a fixed-length length prefix.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Charsetstatic final intThe default maximum data lengthstatic final intThe default length for the prefixprivate intprivate int -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new PrefixedStringEncoder instancePrefixedStringEncoder(Charset charset) Creates a new PrefixedStringEncoder instancePrefixedStringEncoder(Charset charset, int prefixLength) Creates a new PrefixedStringEncoder instancePrefixedStringEncoder(Charset charset, int prefixLength, int maxDataLength) Creates a new PrefixedStringEncoder instance -
Method Summary
Modifier and TypeMethodDescriptionvoidencode(IoSession session, Object message, ProtocolEncoderOutput out) Encodes higher-level message objects into binary or protocol-specific data.intGets the maximum number of bytes allowed for encoding a single String *intGets the length of the length prefix (1, 2, or 4)voidsetMaxDataLength(int maxDataLength) Sets the maximum number of bytes allowed for encoding a single String (including the prefix)voidsetPrefixLength(int prefixLength) Sets the number of bytes used by the length prefixMethods inherited from class ProtocolEncoderAdapter
dispose
-
Field Details
-
DEFAULT_PREFIX_LENGTH
public static final int DEFAULT_PREFIX_LENGTHThe default length for the prefix- See Also:
-
DEFAULT_MAX_DATA_LENGTH
public static final int DEFAULT_MAX_DATA_LENGTHThe default maximum data length- See Also:
-
charset
-
prefixLength
private int prefixLength -
maxDataLength
private int maxDataLength
-
-
Constructor Details
-
PrefixedStringEncoder
-
PrefixedStringEncoder
-
PrefixedStringEncoder
-
PrefixedStringEncoder
public PrefixedStringEncoder()Creates a new PrefixedStringEncoder instance
-
-
Method Details
-
setPrefixLength
public void setPrefixLength(int prefixLength) Sets the number of bytes used by the length prefix- Parameters:
prefixLength- the length of the length prefix (1, 2, or 4)
-
getPrefixLength
public int getPrefixLength()Gets the length of the length prefix (1, 2, or 4)- Returns:
- length of the length prefix
-
setMaxDataLength
public void setMaxDataLength(int maxDataLength) Sets the maximum number of bytes allowed for encoding a single String (including the prefix)The encoder will throw a
IllegalArgumentExceptionwhen more bytes are needed to encode a String value. The default value isDEFAULT_MAX_DATA_LENGTH.- Parameters:
maxDataLength- maximum number of bytes allowed for encoding a single String
-
getMaxDataLength
public int getMaxDataLength()Gets the maximum number of bytes allowed for encoding a single String *- Returns:
- maximum number of bytes allowed for encoding a single String (prefix included)
-
encode
Encodes higher-level message objects into binary or protocol-specific data. MINA invokesProtocolEncoder.encode(IoSession, Object, ProtocolEncoderOutput)method with message which is popped from the session write queue, and then the encoder implementation puts encoded messages (typicallyIoBuffers) intoProtocolEncoderOutput.- Parameters:
session- The current Sessionmessage- the message to encodeout- TheProtocolEncoderOutputthat will receive the encoded message- Throws:
Exception- if the message violated protocol specification
-