JDK-8180451 : ByteArrayInputStream should override readAllBytes, readNBytes, and transferTo
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-05-16
  • Updated: 2023-12-07
  • Resolved: 2018-03-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11
11 b07Fixed
Related Reports
CSR :  
Duplicate :  
Relates :  
Relates :  
Description
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.
Comments
URL: http://hg.openjdk.java.net/jdk/jdk/rev/49e0f711bb2b User: bpb Date: 2018-03-23 17:20:38 +0000
23-03-2018