com.kuka.comm.codec
Class Decoder<I,O>

java.lang.Object
  extended by com.kuka.comm.codec.Decoder<I,O>
Type Parameters:
I - the input type of this decoder
O - the output type of this decoder
Direct Known Subclasses:
ByteOrderDecoder, EnclosingTokenDecoder, LengthDecoder, SwitchDecoder, TokenDecoder

public abstract class Decoder<I,O>
extends Object

Abstract realization of a decoder interface.

Decoders must be implemented in a thread-safe manner. They should either be stateless or their state should not be changed while they are being used by a Connection or a Server.


Constructor Summary
Decoder()
           
 
Method Summary
<T> Decoder<I,T>
concat(Decoder<O,T> next)
          This method concatenates two decoders, i.e. they will be executed in a row.
 O decode(I in)
          Decodes the given input and returns the resulting object.
protected abstract  O decodeImpl(I in)
          Realization of the decoding method to be implemented in subclasses.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Decoder

public Decoder()
Method Detail

decode

public final O decode(I in)
               throws DecoderException
Decodes the given input and returns the resulting object.

This method is usually called in a connection (see Connection) to decode incoming messages. But it can also be used by other decoders.

Returning null means the decoder could not finish its job (e.g. because the input was incomplete). The decoding will be cancelled, i.e. concatenated decoders coming after this decoder will not be called, and the decoding process will restart, when more data is available. Throwing an exception means an error occurred during decoding. The data read so far will be discarded.

Parameters:
in - the input for this decoder, usually the message to be decoded
Returns:
the decoded message, or null if the input was incomplete
Throws:
DecoderException - if an error occurred during decoding

concat

public final <T> Decoder<I,T> concat(Decoder<O,T> next)
This method concatenates two decoders, i.e. they will be executed in a row. The output of the first decoder will be the input for the second decoder.

Type Parameters:
T - the output type
Parameters:
next - the decoder to be executed after this one
Returns:
the resulting decoder containing both the given decoder and this one

decodeImpl

protected abstract O decodeImpl(I in)
                         throws DecoderException
Realization of the decoding method to be implemented in subclasses. This method will be called by the decode(Object) method.

Return null to indicate that the decoder could not finish its job (e.g. because the input was incomplete). The decoding will be cancelled, i.e. concatenated decoders coming after this decoder will not be called, and the decoding process will restart, when more data is available. Throw an exception to indicate that an error occurred during decoding. The data read so far will be discarded.

Parameters:
in - the input for this decoder, usually the message to be decoded
Returns:
the decoded message, or null if the input was incomplete
Throws:
DecoderException - if an error occurred during decoding


Copyright © 2019. All rights reserved.