in protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/ProtonScanningContext.java [103:150]
public boolean matches(StreamTypeDecoder<?> typeDecoder, InputStream stream, int encodedSize, Consumer<Type> matchConsumer) {
if (!stream.markSupported()) {
throw new UnsupportedOperationException("Type scanner requires a stream with mark and reset support");
}
if (isComplete() || !expectedType.equals(typeDecoder.getTypeClass())) {
return false;
}
try {
for (int i = 0; i < matched.length; ++i) {
if (matched[i]) {
continue;
}
final ProtonBuffer candidate = encodedEntries.get(i);
boolean matchFound = true;
if (candidate.getReadableBytes() == encodedSize) {
stream.mark(encodedSize);
try {
for (int j = 0; j < encodedSize; ++j) {
if (candidate.getByte(j) != stream.read()) {
matchFound = false;
break;
}
}
} finally {
stream.reset();
}
if (matchFound) {
matched[i] = true;
if (matchConsumer != null) {
matchConsumer.accept(entries.get(i));
}
return true;
}
}
}
} catch (IOException ex) {
throw new DecodeException("Error while scanning input stream", ex);
}
return false;
}