com.kuka.comm.codec.bytebuffer
Class SegmenterUtil

java.lang.Object
  extended by com.kuka.comm.codec.bytebuffer.SegmenterUtil

public final class SegmenterUtil
extends Object

Helper class for searching a byte sequence as a subsequence within another byte sequence.


Nested Class Summary
static class SegmenterUtil.FoundToken
          Represents the found token, i.e. its position and the index of the token that has been found.
 
Field Summary
static int NO_TOKEN
          Special value for the token index, indicating that no token has been found.
static int NOT_FOUND
          Special value for the token position, indicating that no token has been found.
 
Method Summary
static int indexOf(byte[] token, byte[] buffer)
          Tries to find token as a subsequence within buffer and returns the token's position, or NOT_FOUND if the token was not found.
static int indexOf(byte[] token, byte[] buffer, int begin, int end)
          Tries to find token as a subsequence within buffer and returns the token's position, or NOT_FOUND if the token was not found.
static int indexOf(byte[] token, ByteBuffer buffer)
          Tries to find token as a subsequence within buffer and returns the token's position, or NOT_FOUND if the token was not found.
static int indexOf(byte[] token, ByteBuffer buffer, int begin, int end)
          Tries to find token as a subsequence within buffer and returns the token's position, or NOT_FOUND if the token was not found.
static SegmenterUtil.FoundToken indexOf(List<byte[]> tokens, ByteBuffer buffer)
          Tries to find one of the given tokens as a subsequence within buffer and returns the token's position and the token's index.
static SegmenterUtil.FoundToken indexOf(List<byte[]> tokens, ByteBuffer buffer, int begin, int end)
          Tries to find one of the given tokens as a subsequence within buffer and returns the token's position and the token's index.
static int indexOfTruncated(byte[] token, ByteBuffer buffer)
          Tries to find token as a subsequence within buffer and returns the token's position, or NOT_FOUND if the token was not found.
static int indexOfTruncated(byte[] token, ByteBuffer buffer, int begin, int end)
          Tries to find token as a subsequence within buffer and returns the token's position, or NOT_FOUND if the token was not found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOT_FOUND

public static final int NOT_FOUND
Special value for the token position, indicating that no token has been found.

See Also:
Constant Field Values

NO_TOKEN

public static final int NO_TOKEN
Special value for the token index, indicating that no token has been found.

See Also:
Constant Field Values
Method Detail

indexOf

public static int indexOf(byte[] token,
                          byte[] buffer)
Tries to find token as a subsequence within buffer and returns the token's position, or NOT_FOUND if the token was not found.

Parameters:
token - the token
buffer - the buffer
Returns:
the token's position, or NOT_FOUND if the token was not found

indexOf

public static int indexOf(byte[] token,
                          byte[] buffer,
                          int begin,
                          int end)
Tries to find token as a subsequence within buffer and returns the token's position, or NOT_FOUND if the token was not found. The search within the buffer is restricted to the range [begin,end).

Parameters:
token - the token
buffer - the buffer
begin - the beginning of the search interval defined as [begin,end)
end - the end of the search interval defined as [begin,end)
Returns:
the token's position, or NOT_FOUND if the token was not found

indexOf

public static int indexOf(byte[] token,
                          ByteBuffer buffer)
Tries to find token as a subsequence within buffer and returns the token's position, or NOT_FOUND if the token was not found.

Parameters:
token - the token
buffer - the buffer
Returns:
the token's position, or NOT_FOUND if the token was not found

indexOf

public static int indexOf(byte[] token,
                          ByteBuffer buffer,
                          int begin,
                          int end)
Tries to find token as a subsequence within buffer and returns the token's position, or NOT_FOUND if the token was not found. The search within the buffer is restricted to the range [begin,end).

Parameters:
token - the token
buffer - the buffer
begin - the beginning of the search interval defined as [begin,end)
end - the end of the search interval defined as [begin,end)
Returns:
the token's position, or NOT_FOUND if the token was not found

indexOf

public static SegmenterUtil.FoundToken indexOf(List<byte[]> tokens,
                                               ByteBuffer buffer)
Tries to find one of the given tokens as a subsequence within buffer and returns the token's position and the token's index. Only the first token that matches is reported. If no token has been found, then the position and index of the token will correspond to NOT_FOUND and NO_TOKEN.

Parameters:
tokens - the lost of tokens to search for
buffer - the buffer
Returns:
the token's position and index, or NOT_FOUND and NOT_FOUND if the token was not found

indexOf

public static SegmenterUtil.FoundToken indexOf(List<byte[]> tokens,
                                               ByteBuffer buffer,
                                               int begin,
                                               int end)
Tries to find one of the given tokens as a subsequence within buffer and returns the token's position and the token's index. Only the first token that matches is reported. If no token has been found, then the position and index of the token will correspond to NOT_FOUND and NO_TOKEN. The search within the buffer is restricted to the range [begin,end).

Parameters:
tokens - the lost of tokens to search for
buffer - the buffer
begin - the beginning of the search interval defined as [begin,end)
end - the end of the search interval defined as [begin,end)
Returns:
the token's position and index, or NOT_FOUND and NOT_FOUND if the token was not found

indexOfTruncated

public static int indexOfTruncated(byte[] token,
                                   ByteBuffer buffer)
Tries to find token as a subsequence within buffer and returns the token's position, or NOT_FOUND if the token was not found. The token may also be found as a truncated version at the end of the buffer.

Parameters:
token - the token
buffer - the buffer
Returns:
the token's position, or NOT_FOUND if the token was not found

indexOfTruncated

public static int indexOfTruncated(byte[] token,
                                   ByteBuffer buffer,
                                   int begin,
                                   int end)
Tries to find token as a subsequence within buffer and returns the token's position, or NOT_FOUND if the token was not found. The token may also be found as a truncated version at the end of the buffer. The search within the buffer is restricted to the range [begin,end).

Parameters:
token - the token
buffer - the buffer
begin - the beginning of the search interval defined as [begin,end)
end - the end of the search interval defined as [begin,end)
Returns:
the token's position, or NOT_FOUND if the token was not found


Copyright © 2019. All rights reserved.