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

java.lang.Object
  extended by com.kuka.comm.codec.Encoder<I,O>
Type Parameters:
I - the input type of this encoder
O - the output type of this encoder
Direct Known Subclasses:
ByteOrderEncoder, EnclosingTokenEncoder, LengthEncoder, SwitchEncoder, TokenEncoder

public abstract class Encoder<I,O>
extends Object

A basic encoder. This class encapsulates different encoding implementations into a generic encode(Object, Object) method call.

Encoders 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.

Moreover a implementation to concatenate two encoder has been realized by this class. As far as you just want to define the way of encoding, this class is the right one. Otherwise you have to derive the Encoder interface directly.

A encodeImpl(Object, Object) method needs to be derived by more specific implementations.


Nested Class Summary
protected static class Encoder.EncoderContext
          This class can be used to do some more encoding after a concatenated encoder finished.
 
Constructor Summary
Encoder()
           
 
Method Summary
 Encoder<I,O> concat(Encoder<I,O> next)
          This method concatenates two encoders, i.e. they will be executed in a row.
 void encode(I in, O out)
          Encodes the given input into to the given output object.
protected  void encodeImpl(I in, O out)
          Override this method to implement encoding process.
protected  void encodeImpl(I in, O out, Encoder.EncoderContext context)
          Override this method to implement encoding process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Encoder

public Encoder()
Method Detail

encode

public final void encode(I in,
                         O out)
                  throws EncoderException
Encodes the given input into to the given output object.

This method is usually called in the send method of a connection (see Connection.send(Object)) to encode the method that should be sent. But it can also be used by other encoders.

Parameters:
in - the input for this encoder, usually the message to be encoded
out - the output for this encoder, usually the encoded message
Throws:
EncoderException - if an error occurred during encoding

concat

public final Encoder<I,O> concat(Encoder<I,O> next)
This method concatenates two encoders, i.e. they will be executed in a row.

Parameters:
next - the encoder to be executed after this one
Returns:
the resulting encoder containing both the given encoder and this one

encodeImpl

protected void encodeImpl(I in,
                          O out)
                   throws EncoderException
Override this method to implement encoding process.

Note: You should override either this method or encodeImpl(Object, Object, EncoderContext). Overriding both will have no effect, i.e. only encodeImpl(Object, Object, EncoderContext) will be called.

Parameters:
in - the input for this encoder
out - the output for this encoder
Throws:
EncoderException - if an error occurred during encoding
See Also:
encodeImpl(Object, Object, EncoderContext)

encodeImpl

protected void encodeImpl(I in,
                          O out,
                          Encoder.EncoderContext context)
                   throws EncoderException
Override this method to implement encoding process.

The context is currently only taken into account if this encoder is concatenated to another one concat(Encoder).

Note: You should override either this method or encodeImpl(Object, Object). Overriding both will have no effect, i.e. only encodeImpl(Object, Object, EncoderContext) will be called.

Parameters:
in - the input for this encoder
out - the output for this encoder
context - can be used to do some more encoding after a concatenated encoder finished
Throws:
EncoderException - if an error occurred during encoding
See Also:
encodeImpl(Object, Object)


Copyright © 2019. All rights reserved.