org.apache.mina.filter.codec.prefixedstring

## Class PrefixedStringCodecFactory

- java.lang.Object
- - org.apache.mina.filter.codec.prefixedstring.PrefixedStringCodecFactory

- All Implemented Interfaces:
    ProtocolCodecFactory

      public class PrefixedStringCodecFactory
      extends Object
      implements ProtocolCodecFactory

  A `ProtocolCodecFactory` that performs encoding and decoding of a Java String object using a fixed-length length prefix.
  Author:
    Apache MINA Project

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PrefixedStringCodecFactory()`
    `PrefixedStringCodecFactory(Charset charset)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `ProtocolDecoder` | `getDecoder(IoSession session)` Returns a new (or reusable) instance of `ProtocolDecoder` which decodes binary or protocol-specific data into message objects.
    `int` | `getDecoderMaxDataLength()` Returns the allowed maximum size of a decoded string.
    `int` | `getDecoderPrefixLength()` Gets the length of the length prefix (1, 2, or 4) used by the decoder
    `ProtocolEncoder` | `getEncoder(IoSession session)` Returns a new (or reusable) instance of `ProtocolEncoder` which encodes message objects into binary or protocol-specific data.
    `int` | `getEncoderMaxDataLength()` Returns the allowed maximum size of an encoded string.
    `int` | `getEncoderPrefixLength()` Gets the length of the length prefix (1, 2, or 4) used by the encoder
    `void` | `setDecoderMaxDataLength(int maxDataLength)` Sets the maximum allowed value specified as data length in the decoded data
    `void` | `setDecoderPrefixLength(int prefixLength)` Sets the length of the prefix used by the decoder
    `void` | `setEncoderMaxDataLength(int maxDataLength)` Sets the allowed maximum size of an encoded String.
    `void` | `setEncoderPrefixLength(int prefixLength)` Sets the length of the prefix used by the encoder

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

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

- - ### Constructor Detail

    - #### PrefixedStringCodecFactory

          public PrefixedStringCodecFactory(Charset charset)

    - #### PrefixedStringCodecFactory

          public PrefixedStringCodecFactory()

  - ### Method Detail

    - #### getEncoderMaxDataLength

          public int getEncoderMaxDataLength()

      Returns the allowed maximum size of an encoded string. If the size of the encoded String exceeds this value, the encoder will throw a `IllegalArgumentException`. The default value is `PrefixedStringEncoder.DEFAULT_MAX_DATA_LENGTH`.

      This method does the same job as `PrefixedStringEncoder.setMaxDataLength(int)`.
      Returns:
        the allowed maximum size of an encoded string.

    - #### setEncoderMaxDataLength

          public void setEncoderMaxDataLength(int maxDataLength)

      Sets the allowed maximum size of an encoded String. If the size of the encoded String exceeds this value, the encoder will throw a `IllegalArgumentException`. The default value is `PrefixedStringEncoder.DEFAULT_MAX_DATA_LENGTH`.

      This method does the same job as `PrefixedStringEncoder.getMaxDataLength()`.
      Parameters:
        `maxDataLength` - allowed maximum size of an encoded String.

    - #### getDecoderMaxDataLength

          public int getDecoderMaxDataLength()

      Returns the allowed maximum size of a decoded string.

      This method does the same job as `PrefixedStringEncoder.setMaxDataLength(int)`.

      Returns:
        the allowed maximum size of an encoded string.
      See Also:
        `setDecoderMaxDataLength(int)`

    - #### setDecoderMaxDataLength

          public void setDecoderMaxDataLength(int maxDataLength)

      Sets the maximum allowed value specified as data length in the decoded data

      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 `PrefixedStringDecoder.DEFAULT_MAX_DATA_LENGTH`. This method does the same job as `PrefixedStringDecoder.setMaxDataLength(int)`.

      Parameters:
        `maxDataLength` - maximum allowed value specified as data length in the incoming data

    - #### setDecoderPrefixLength

          public void setDecoderPrefixLength(int prefixLength)

      Sets the length of the prefix used by the decoder
      Parameters:
        `prefixLength` - the length of the length prefix (1, 2, or 4)

    - #### getDecoderPrefixLength

          public int getDecoderPrefixLength()

      Gets the length of the length prefix (1, 2, or 4) used by the decoder
      Returns:
        length of the length prefix

    - #### setEncoderPrefixLength

          public void setEncoderPrefixLength(int prefixLength)

      Sets the length of the prefix used by the encoder
      Parameters:
        `prefixLength` - the length of the length prefix (1, 2, or 4)

    - #### getEncoderPrefixLength

          public int getEncoderPrefixLength()

      Gets the length of the length prefix (1, 2, or 4) used by the encoder
      Returns:
        length of the length prefix

    - #### getEncoder

          public ProtocolEncoder getEncoder(IoSession session)
                                     throws Exception

      Description copied from interface: `ProtocolCodecFactory`
      Returns a new (or reusable) instance of `ProtocolEncoder` which encodes message objects into binary or protocol-specific data.
      Specified by:
        `getEncoder` in interface `ProtocolCodecFactory`
      Throws:
        `Exception`

    - #### getDecoder

          public ProtocolDecoder getDecoder(IoSession session)
                                     throws Exception

      Description copied from interface: `ProtocolCodecFactory`
      Returns a new (or reusable) instance of `ProtocolDecoder` which decodes binary or protocol-specific data into message objects.
      Specified by:
        `getDecoder` in interface `ProtocolCodecFactory`
      Throws:
        `Exception`

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