Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
2.15.1
-
None
-
None
Description
The current JavaDoc of the PeekableInputStream states "Returns whether the next bytes in the buffer are as given by sourceBuffer.". When trying to using it I expected the following to work:
PeekableInputStream stream = new PeekableInputStream(
new ByteArrayInputStream("Some text buffer".getBytes(StandardCharsets.UTF_8)));assertTrue(stream.peek("Some".getBytes(StandardCharsets.UTF_8)));
However this fails because the current implementation checks if the available bytes on the stream exactly match the bytes in the stream, so if there is more data available, it will return false!
If this is the intended behavior, it should be made more prominent in the JavaDoc.
P.S.: I am not sure how useful such an implementation is as at least for me most such use-cases are of type "startsWith", not "equals".