org.apache.mina.codec.textline

## Class TextLineDecoder

- java.lang.Object
- - org.apache.mina.codec.textline.TextLineDecoder

All Implemented Interfaces:
  ProtocolDecoder<ByteBuffer,String,TextLineDecoder.Context>

    public class TextLineDecoder
    extends Object
    implements ProtocolDecoder<ByteBuffer,String,TextLineDecoder.Context>

A `ProtocolDecoder` which decodes a text line into a string.

Author:
  Apache MINA Project

### Nested Class Summary

Nested Classes
`class` `TextLineDecoder.Context` A Context used during the decoding of a lin.

### Constructor Summary

Constructors
Constructor and Description
`TextLineDecoder()` Creates a new instance with the current default `Charset` and `LineDelimiter.AUTO` delimiter.
`TextLineDecoder(Charset charset)` Creates a new instance with the spcified `charset` and `LineDelimiter.AUTO` delimiter.
`TextLineDecoder(Charset charset, LineDelimiter delimiter)` Creates a new instance with the specified `charset` and the specified `delimiter`.
`TextLineDecoder(Charset charset, String delimiter)` Creates a new instance with the spcified `charset` and the specified `delimiter`.
`TextLineDecoder(LineDelimiter delimiter)` Creates a new instance with the current default `Charset` and the specified `delimiter`.
`TextLineDecoder(String delimiter)` Creates a new instance with the current default `Charset` and the specified `delimiter`.

### Method Summary

Methods
`TextLineDecoder.Context` `createDecoderState()` Create a new session context for this decoder
`String` `decode(ByteBuffer in, TextLineDecoder.Context ctx)` Decode binary or protocol-specific content of type `INPUT` into higher-level protocol message objects, of type OUTPUT
`void` `finishDecode(TextLineDecoder.Context ctx)` Finish decoding, for example if the decoder accumulated some unused input, it should discard it, or throw an Exception
`int` `getBufferLength()` Returns the allowed buffer size used to store the decoded line in the Context instance.
`int` `getMaxLineLength()` Returns the allowed maximum size of the line to be decoded.
`void` `setBufferLength(int bufferLength)` Sets the default buffer size.
`void` `setMaxLineLength(int maxLineLength)` Sets the allowed maximum size of the line to be decoded.

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

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

### Constructor Detail

#### TextLineDecoder

    public TextLineDecoder()

Creates a new instance with the current default `Charset` and `LineDelimiter.AUTO` delimiter.

#### TextLineDecoder

    public TextLineDecoder(String delimiter)

Creates a new instance with the current default `Charset` and the specified `delimiter`.

#### TextLineDecoder

    public TextLineDecoder(LineDelimiter delimiter)

Creates a new instance with the current default `Charset` and the specified `delimiter`.

#### TextLineDecoder

    public TextLineDecoder(Charset charset)

Creates a new instance with the spcified `charset` and `LineDelimiter.AUTO` delimiter.

#### TextLineDecoder

    public TextLineDecoder(Charset charset,
                   String delimiter)

Creates a new instance with the spcified `charset` and the specified `delimiter`.

#### TextLineDecoder

    public TextLineDecoder(Charset charset,
                   LineDelimiter delimiter)

Creates a new instance with the specified `charset` and the specified `delimiter`.

### Method Detail

#### getMaxLineLength

    public int getMaxLineLength()

Returns the allowed maximum size of the line to be decoded. If the size of the line to be decoded exceeds this value, the decoder will throw a `BufferDataException`. The default value is `1024` (1KB).

#### setMaxLineLength

    public void setMaxLineLength(int maxLineLength)

Sets the allowed maximum size of the line to be decoded. If the size of the line to be decoded exceeds this value, the decoder will throw a `BufferDataException`. The default value is `1024` (1KB).

#### setBufferLength

    public void setBufferLength(int bufferLength)

Sets the default buffer size. This buffer is used in the Context to store the decoded line.

Parameters:
  `bufferLength` - The default bufer size

#### getBufferLength

    public int getBufferLength()

Returns the allowed buffer size used to store the decoded line in the Context instance.

#### createDecoderState

    public TextLineDecoder.Context createDecoderState()

Description copied from interface: `ProtocolDecoder`
Create a new session context for this decoder

Specified by:
  `createDecoderState` in interface `ProtocolDecoder<ByteBuffer,String,TextLineDecoder.Context>`
Returns:
  the newly created context

#### decode

    public String decode(ByteBuffer in,
                TextLineDecoder.Context ctx)

Decode binary or protocol-specific content of type `INPUT` into higher-level protocol message objects, of type OUTPUT

Specified by:
  `decode` in interface `ProtocolDecoder<ByteBuffer,String,TextLineDecoder.Context>`
Parameters:
  `in` - the received message to decode
  `ctx` - the decoding context (will be stored in the session for the next decode call)
Returns:
  the decoded message or `null` if nothing was decoded

#### finishDecode

    public void finishDecode(TextLineDecoder.Context ctx)

Finish decoding, for example if the decoder accumulated some unused input, it should discard it, or throw an Exception

Specified by:
  `finishDecode` in interface `ProtocolDecoder<ByteBuffer,String,TextLineDecoder.Context>`