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 theIncrementalMessageTokenizer
class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears and temporary data stored in the tokenizer.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
.protected static int
indexOf
(byte[] source, byte[] pattern, int offset, int maxIndex) Finds the index of the first occurrence of bytes specified by thepattern
insource
.void
processData
(InputStream stream) Processes passed data.protected static int
selectIndex
(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 theIncrementalMessageTokenizer
class.- Parameters:
bufferSize
- the size of the internal buffer used to store incomplete messages- Throws:
IllegalArgumentException
- thebufferSize
is 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:
processData
in interfaceMessageTokenizer
- Specified by:
processData
in classMessageTokenizerBase
- Parameters:
stream
- AInputStream
containing data to be tokenized.- Throws:
IllegalArgumentException
- thestream
is 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 maximumsource
index to be included in the search.- Returns:
- The index of the first occurrence or -1 if the
MESSAGE_END
does 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 thepattern
insource
. 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 maximumsource
index to be included in the search.- Returns:
- The index of the first occurrence or -1 if the
pattern
does 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.
-