com.kuka.comm.codec.bytebuffer
Class TokenDecoder

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

public final class TokenDecoder
extends Decoder<ByteBuffer,ByteBuffer>

A TokenDecoder tries to find a specified token in a byte buffer.

By default the token will be consumed when found, i.e. the byte buffer passed to a concatenated decoder does not include the token (see setTokenIncluded(boolean)). If the token is not consumed the byte buffer will start at the first byte of the token.


Constructor Summary
TokenDecoder(byte[] token)
          Creates a decoder that will seek to the first occurrence of the given byte subsequence (token).
TokenDecoder(String token)
          Creates a decoder that will seek to the first occurrence of the given byte subsequence (token).
TokenDecoder(String token, Charset charset)
          Creates a decoder that will seek to the first occurrence of the given byte subsequence (token).
 
Method Summary
protected  ByteBuffer decodeImpl(ByteBuffer in)
          Realization of the decoding method to be implemented in subclasses.
 boolean isTokenIncluded()
          Returns true if the token is included in the resulting byte buffer.
 TokenDecoder setTokenIncluded(boolean consume)
          If set to true the token is included in the resulting byte buffer.
 
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

TokenDecoder

public TokenDecoder(String token)
Creates a decoder that will seek to the first occurrence of the given byte subsequence (token). As charset the default charset of this Java virtual machine will be used (see Charset.defaultCharset(). By default the token will be consumed when found (see setTokenIncluded(boolean)).

Parameters:
token - the subsequence to be searched for

TokenDecoder

public TokenDecoder(String token,
                    Charset charset)
Creates a decoder that will seek to the first occurrence of the given byte subsequence (token). By default the token will be consumed when found (see setTokenIncluded(boolean)).

Parameters:
token - the subsequence to be searched for
charset - the charset of the string

TokenDecoder

public TokenDecoder(byte[] token)
Creates a decoder that will seek to the first occurrence of the given byte subsequence (token). By default the token will be consumed when found (see setTokenIncluded(boolean)).

Parameters:
token - the token to decode
Method Detail

isTokenIncluded

public boolean isTokenIncluded()
Returns true if the token is included in the resulting byte buffer.

Returns:
true if the token is included in the resulting byte buffer.
See Also:
setTokenIncluded(boolean)

setTokenIncluded

public TokenDecoder setTokenIncluded(boolean consume)
If set to true the token is included in the resulting byte buffer.

Parameters:
consume - if the token should be included in the resulting byte buffer
Returns:
this decoder
See Also:
isTokenIncluded()

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.