Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-855

Clarify behavior of PeekableInputStream.peek() in Javadoc

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.15.1
    • None
    • Streams/Writers
    • 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".

      Attachments

        Activity

          People

            Unassigned Unassigned
            dominik.stadler@gmx.at Dominik Stadler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: