Class IncrementalMessageTokenizer
java.lang.Object
com.sportradar.livedata.sdk.proto.common.MessageTokenizerBase
com.sportradar.livedata.sdk.proto.common.IncrementalMessageTokenizer
- All Implemented Interfaces:
MessageTokenizer
Represents a tokenizer where data arrives in chunks.
Contains logic for low-level byte splitting.
- Author:
- uros.bregar
-
Field Summary
FieldsFields inherited from class com.sportradar.livedata.sdk.proto.common.MessageTokenizerBase
listener -
Constructor Summary
ConstructorsConstructorDescriptionIncrementalMessageTokenizer(int bufferSize) Initializes a new instance of theIncrementalMessageTokenizerclass. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears and temporary data stored in the tokenizer.protected intfindElementEnd(byte[] source, byte[] elementName, int offset, int maxIndex) Finds the index of the first occurrence of bytes representing the end of the element in thesource.protected static intindexOf(byte[] source, byte[] pattern, int offset, int maxIndex) Finds the index of the first occurrence of bytes specified by thepatterninsource.voidprocessData(InputStream stream) Processes passed data.protected static intselectIndex(int index1, int index2) returns the index which is smaller but is not equal to -1.Methods inherited from class com.sportradar.livedata.sdk.proto.common.MessageTokenizerBase
notifyListener, setListener
-
Field Details
-
ENCODING
The name of the used encoding
-
-
Constructor Details
-
IncrementalMessageTokenizer
public IncrementalMessageTokenizer(int bufferSize) Initializes a new instance of theIncrementalMessageTokenizerclass.- Parameters:
bufferSize- the size of the internal buffer used to store incomplete messages- Throws:
IllegalArgumentException- thebufferSizeis smaller than or equal to 0.
-
-
Method Details
-
clear
public void clear()Clears and temporary data stored in the tokenizer. -
processData
Processes passed data. If passed data and any previously stored data represent a whole message theMessageTokenizerListener.onMessageReady(byte[])method is invoked- Specified by:
processDatain interfaceMessageTokenizer- Specified by:
processDatain classMessageTokenizerBase- Parameters:
stream- AInputStreamcontaining data to be tokenized.- Throws:
IllegalArgumentException- thestreamis a null reference.ProtocolException- the data could not be processed either because the buffer is fullSdkException
-
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 thesource. 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 theoffset. The returned index points to the '>' character.- Parameters:
source- the array to be searchedelementName- the byte array representation of the element's nameoffset- offset the index specifying where in the source array to begin the search.maxIndex- specifies the maximumsourceindex to be included in the search.- Returns:
- The index of the first occurrence or -1 if the
MESSAGE_ENDdoes not exist in thesource.
-
indexOf
protected static int indexOf(byte[] source, byte[] pattern, int offset, int maxIndex) Finds the index of the first occurrence of bytes specified by thepatterninsource. The search starts at the location specified by theoffset. The returned index points to the first byte of the searched sequence.- Parameters:
source- the source of the searchpattern- the bytes to be found in the source.offset- the index specifying where in the source array to begin the search.maxIndex- specifies the maximumsourceindex to be included in the search.- Returns:
- The index of the first occurrence or -1 if the
patterndoes not exist in thesource.
-
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.
-