org.apache.mina.filter.codec.prefixedstring

## Class PrefixedStringEncoder

- java.lang.Object
- - org.apache.mina.filter.codec.ProtocolEncoderAdapter
  - - org.apache.mina.filter.codec.prefixedstring.PrefixedStringEncoder

- All Implemented Interfaces:
    ProtocolEncoder

      public class PrefixedStringEncoder
      extends ProtocolEncoderAdapter

  A `ProtocolEncoder` which encodes a string using a fixed-length length prefix.
  Author:
    Apache MINA Project

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_MAX_DATA_LENGTH`
    `static int` | `DEFAULT_PREFIX_LENGTH`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PrefixedStringEncoder()`
    `PrefixedStringEncoder(Charset charset)`
    `PrefixedStringEncoder(Charset charset, int prefixLength)`
    `PrefixedStringEncoder(Charset charset, int prefixLength, int maxDataLength)`

  - ### Method Summary

    Methods
    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)
    `void` | `setPrefixLength(int prefixLength)` Sets the number of bytes used by the length prefix

    - ### Methods inherited from class org.apache.mina.filter.codec.ProtocolEncoderAdapter

      `dispose`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_PREFIX_LENGTH

          public static final int DEFAULT_PREFIX_LENGTH

      See Also:
        Constant Field Values

    - #### DEFAULT_MAX_DATA_LENGTH

          public static final int DEFAULT_MAX_DATA_LENGTH

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### PrefixedStringEncoder

          public PrefixedStringEncoder(Charset charset,
                               int prefixLength,
                               int maxDataLength)

    - #### PrefixedStringEncoder

          public PrefixedStringEncoder(Charset charset,
                               int prefixLength)

    - #### PrefixedStringEncoder

          public PrefixedStringEncoder(Charset charset)

    - #### PrefixedStringEncoder

          public PrefixedStringEncoder()

  - ### Method Detail

    - #### 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 `IllegalArgumentException` when more bytes are needed to encode a String value. The default value is `DEFAULT_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

          public void encode(IoSession session,
                    Object message,
                    ProtocolEncoderOutput out)
                      throws Exception

      Description copied from interface: `ProtocolEncoder`
      Encodes higher-level message objects into binary or protocol-specific data. MINA invokes `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`.
      Throws:
        `Exception` - if the message violated protocol specification

Copyright © 2004-2012 Apache MINA Project. All Rights Reserved.