You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2025/03/23 13:51:00 UTC

[jira] [Commented] (IO-855) Clarify behavior of PeekableInputStream.peek() in Javadoc

    [ https://issues.apache.org/jira/browse/IO-855?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17937707#comment-17937707 ] 

Gary D. Gregory commented on IO-855:
------------------------------------

Ping [~jochen@apache.org]

> 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
>            Priority: Minor
>
> 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)