Class IncrementalMessageTokenizer

java.lang.Object
com.sportradar.livedata.sdk.proto.common.MessageTokenizerBase
com.sportradar.livedata.sdk.proto.common.IncrementalMessageTokenizer
All Implemented Interfaces:
MessageTokenizer

public class IncrementalMessageTokenizer extends MessageTokenizerBase
Represents a tokenizer where data arrives in chunks. Contains logic for low-level byte splitting.
Author:
uros.bregar
  • Field Details

    • ENCODING

      public static final Charset ENCODING
      The name of the used encoding
  • Constructor Details

    • IncrementalMessageTokenizer

      public IncrementalMessageTokenizer(int bufferSize)
      Initializes a new instance of the IncrementalMessageTokenizer class.
      Parameters:
      bufferSize - the size of the internal buffer used to store incomplete messages
      Throws:
      IllegalArgumentException - the bufferSize is smaller than or equal to 0.
  • Method Details

    • clear

      public void clear()
      Clears and temporary data stored in the tokenizer.
    • processData

      public void processData(InputStream stream) throws SdkException
      Processes passed data. If passed data and any previously stored data represent a whole message the MessageTokenizerListener.onMessageReady(byte[]) method is invoked
      Specified by:
      processData in interface MessageTokenizer
      Specified by:
      processData in class MessageTokenizerBase
      Parameters:
      stream - A InputStream containing data to be tokenized.
      Throws:
      IllegalArgumentException - the stream is a null reference.
      ProtocolException - the data could not be processed either because the buffer is full
      SdkException
    • findElementEnd

      protected int findElementEnd(byte[] source, byte[] elementName, int offset, int maxIndex)
      Finds the index of the first occurrence of bytes representing the end of the element in the source. The end of the element can be specified in a normal format '@lt;/elementName>' or the shorten one (/>) but must be followed by double LF/CR combination. The search starts at the location specified by the offset. The returned index points to the '>' character.
      Parameters:
      source - the array to be searched
      elementName - the byte array representation of the element's name
      offset - offset the index specifying where in the source array to begin the search.
      maxIndex - specifies the maximum source index to be included in the search.
      Returns:
      The index of the first occurrence or -1 if the MESSAGE_END does not exist in the source.
    • indexOf

      protected static int indexOf(byte[] source, byte[] pattern, int offset, int maxIndex)
      Finds the index of the first occurrence of bytes specified by the pattern in source. The search starts at the location specified by the offset. The returned index points to the first byte of the searched sequence.
      Parameters:
      source - the source of the search
      pattern - the bytes to be found in the source.
      offset - the index specifying where in the source array to begin the search.
      maxIndex - specifies the maximum source index to be included in the search.
      Returns:
      The index of the first occurrence or -1 if the pattern does not exist in the source.
    • selectIndex

      protected static int selectIndex(int index1, int index2)
      returns the index which is smaller but is not equal to -1. If both indexes are equal to -1, than -1 is returned.
      Parameters:
      index1 - the first index.
      index2 - the second index
      Returns:
      the index which is smaller but is not equal to -1. If both indexes are equal to -1, than -1 is returned.