Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8180451

ByteArrayInputStream should override readAllBytes, readNBytes, and transferTo

XMLWordPrintable

    • b07

      ByteArrayInputStream inherits methods readAllBytes(), readNBytes() and transferTo() from InputStream. These were added in Java 9.

      Benefits of overriding:

      1) The overridden readAllBytes() and readNBytes() methods should NOT declare "throws IOException" because it cannot occur with these methods. This makes BAIS easier to use.

      2) The overridden methods can be optimized to copy bytes from the internal buffer in a single bulk operation instead of in a copy loop.

      There is a potential compatibility problem with adding these overrides, as a subclass of BAIS might override these methods and declare "throws IOException". This seems fairly unlikely, though. (Ideally, these overrides would have been added in Java 9.)

      It would also be nice if BAIS were able to override read(byte[]) and not declare "throws IOException". This has a worse compatibility problem, though, since this method has been around since 1.0, so there has been a much longer period of time for subclasses to have overridden this method.

      See JDK-8180410 for similar issues with ByteArrayOutputStream.

            bpb Brian Burkhalter
            smarks Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: