You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dominik Stadler (Jira)" <ji...@apache.org> on 2024/04/09 06:32:00 UTC
[jira] [Created] (IO-855) Clarify behavior of PeekableInputStream.peek() in JavaDoc
Dominik Stadler created IO-855:
----------------------------------
Summary: Clarify behavior of PeekableInputStream.peek() in JavaDoc
Key: IO-855
URL: https://issues.apache.org/jira/browse/IO-855
Project: Commons IO
Issue Type: Improvement
Components: Streams/Writers
Affects Versions: 2.15.1
Reporter: Dominik Stadler
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 = {color:#cc7832}new {color}PeekableInputStream(
{color:#cc7832}new {color}ByteArrayInputStream({color:#6a8759}"Some text buffer"{color}.getBytes(StandardCharsets.{color:#9876aa}UTF_8{color}))){color:#cc7832};
{color}{color:#cc7832}
{color}assertTrue(stream.peek({color:#6a8759}"Some"{color}.getBytes(StandardCharsets.{color:#9876aa}UTF_8{color}))){color:#cc7832};
{color}
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".
--
This message was sent by Atlassian Jira
(v8.20.10#820010)