com.kuka.comm.codec.bytebuffer
Class EnclosingTokenDecoder

java.lang.Object
  extended by com.kuka.comm.codec.Decoder<ByteBuffer,ByteBuffer>
      extended by com.kuka.comm.codec.bytebuffer.EnclosingTokenDecoder

public final class EnclosingTokenDecoder
extends Decoder<ByteBuffer,ByteBuffer>

This decoder delimits a payload strictly with a constant prefix and postfix. Hence, it must be given that prefix and postfix are not part of the payload code. Non-prefix bytes in front of the prefix are skipped.


Constructor Summary
EnclosingTokenDecoder(byte[] prefix, byte[] postfix)
          Creates a new enclosing token decoder.
EnclosingTokenDecoder(String prefix, String postfix)
          Creates a new enclosing token decoder.
 
Method Summary
protected  ByteBuffer decodeImpl(ByteBuffer in)
          Realization of the decoding method to be implemented in subclasses.
 boolean isPostfixIncluded()
          Returns true if the postfix should be included.
 boolean isPrefixIncluded()
          Returns true if the prefix should be included.
 EnclosingTokenDecoder setPostfixIncluded(boolean postfixIncluded)
          If set to true the postfix is included in the decoded message.
 EnclosingTokenDecoder setPrefixIncluded(boolean prefixIncluded)
          If set to true the prefix is included in the decoded message.
 
Methods inherited from class com.kuka.comm.codec.Decoder
concat, decode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnclosingTokenDecoder

public EnclosingTokenDecoder(String prefix,
                             String postfix)
Creates a new enclosing token decoder.

Splits the input into data frames, each starting with a prefix (header) and ending with a postfix (footer). The data frame will then be passed to the concatenated decoder.

By default the prefix and postfix are not included. Use setPrefixIncluded(boolean) and setPostfixIncluded(boolean) to change that.

Parameters:
prefix - The prefix. It may not be null or empty. The prefix must be different from the postfix and it may not contain the postfix as a substring.
postfix - The postfix. It may not be null or empty. The postfix must be different from the prefix and it may not contain the prefix as a substring.

EnclosingTokenDecoder

public EnclosingTokenDecoder(byte[] prefix,
                             byte[] postfix)
Creates a new enclosing token decoder.

Splits the input into data frames, each starting with a prefix (header) and ending with a postfix (footer). The data frame will then be passed to the concatenated decoder.

By default the prefix and postfix are not included. Use setPrefixIncluded(boolean) and setPostfixIncluded(boolean) to change that.

Parameters:
prefix - The prefix. It may not be null or empty. The prefix must be different from the postfix and it may not contain the postfix as a substring.
postfix - The postfix. It may not be null or empty. The postfix must be different from the prefix and it may not contain the prefix as a substring.
Method Detail

setPrefixIncluded

public EnclosingTokenDecoder setPrefixIncluded(boolean prefixIncluded)
If set to true the prefix is included in the decoded message.

Parameters:
prefixIncluded - if set to true the prefix is included in the decoded message
Returns:
this decoder
See Also:
setPostfixIncluded(boolean)

isPrefixIncluded

public boolean isPrefixIncluded()
Returns true if the prefix should be included.

Returns:
true if the prefix should be included
See Also:
isPostfixIncluded()

setPostfixIncluded

public EnclosingTokenDecoder setPostfixIncluded(boolean postfixIncluded)
If set to true the postfix is included in the decoded message.

Parameters:
postfixIncluded - if set to true the postfix is included in the decoded message
Returns:
this decoder
See Also:
setPrefixIncluded(boolean)

isPostfixIncluded

public boolean isPostfixIncluded()
Returns true if the postfix should be included.

Returns:
true if the postfix should be included
See Also:
isPrefixIncluded()

decodeImpl

protected ByteBuffer decodeImpl(ByteBuffer in)
                         throws DecoderException
Description copied from class: Decoder
Realization of the decoding method to be implemented in subclasses. This method will be called by the Decoder.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.

Specified by:
decodeImpl in class Decoder<ByteBuffer,ByteBuffer>
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.