Interface StreamScanningContext<Type>
- Type Parameters:
Type
- The concrete type of the entries to be scanned.
- All Known Implementing Classes:
ProtonScanningContext
A scanning context is typically created with both the encoded and unencoded form of the value to be scanned for so that a call to the match function can provide an callback that will be provided the value to be sought without the need to perform a complete decode of the scanned data.
The context is a single threaded actor whose state can be modified during the scanning cycle in order to optimize the number of comparisons done as the scan progresses. The caller must ensure a context is not passed to scanning operations that are occurring concurrently.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Allows for the scanner to optimize reading of encoded data by determining if the target of the matching context has been found in which case the scanner can consume any remaining encoded bytes without regard for the matcher.boolean
matches
(StreamTypeDecoder<?> typeDecoder, InputStream candidate, int candidateLength, Consumer<Type> matchConsumer) Returns true if the encoded entry bytes match against the search domain of the scan matching context and calls the provided matchConsumer
with the original unencoded form of the matched entry.void
reset()
Reset the context to its original state at the end of a complete scan which should allow the context to be used again when a new scan is started (e.g.
-
Method Details
-
reset
void reset()Reset the context to its original state at the end of a complete scan which should allow the context to be used again when a new scan is started (e.g.isComplete()
should start returning false). -
isComplete
boolean isComplete()Allows for the scanner to optimize reading of encoded data by determining if the target of the matching context has been found in which case the scanner can consume any remaining encoded bytes without regard for the matcher. In the completed state any call tomatches(StreamTypeDecoder, InputStream, int, Consumer)
should return false as the target has already been found so that unoptimized scanning can continue calling the match method until the encoded data has been fully scanned.- Returns:
- true if the target of the matching context has already been matched.
-
matches
boolean matches(StreamTypeDecoder<?> typeDecoder, InputStream candidate, int candidateLength, Consumer<Type> matchConsumer) Returns true if the encoded entry bytes match against the search domain of the scan matching context and calls the provided matchConsumer
with the original unencoded form of the matched entry. The caller must provide the size of the encoded value being checked to allow for pass of the source bytes without copying which could contain more entries following the candidate value in question.The implementation must not consume the encoded bytes which requires that the provided
InputStream
support mark and reset of the stream position. The implementation should check for mark support in the provided stream and throw anUnsupportedOperationException
if it is not supported.- Parameters:
typeDecoder
- The stream type decoder of the encoded type that is contained in the buffer.candidate
- Buffer whose first read index is the start of the encoded bytes.candidateLength
- The region of the candidate buffer that contains the encoded bytesmatchConsumer
- An optional consumer that should be called if a match is found.- Returns:
- true if the candidate matches a target in the search domain.
-