RFR: 8080272 Refactor I/O stream copying to use InputStream.transferTo/readAllBytes and Files.copy [v9]

Philippe Marschall github.com+471021+marschall at openjdk.java.net
Tue Feb 9 11:42:34 UTC 2021


On Mon, 8 Feb 2021 20:58:01 GMT, Andrey Turbanov <github.com+741251+turbanoff at openjdk.org> wrote:

>> 8080272  Refactor I/O stream copying to use InputStream.transferTo/readAllBytes and Files.copy
>
> Andrey Turbanov has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8080272: Refactor I/O stream copying to use java.io.InputStream.transferTo
>   fix review comments

src/java.base/share/classes/java/util/jar/JarInputStream.java line 93:

> 91:         if (e != null && JarFile.MANIFEST_NAME.equalsIgnoreCase(e.getName())) {
> 92:             man = new Manifest();
> 93:             byte[] bytes = new BufferedInputStream(this).readAllBytes();

I wonder if it makes sense to avoid reading the entire manifest into a byte[] when we don't need to verify the JAR. This may help avoiding some intermediate allocation and copying. This make be noticeable for some of the larger manifests (Java EE, OSGi, ...). A possible implementation may look like this https://github.com/marschall/jdk/commit/c50880ffb18607077c4da3456b27957d1df8edb7.

In either case since we're calling #readAllBytes I don't see why we are wrapping in a BufferedInputStream rather than calling #readAllBytes directly.

-------------

PR: https://git.openjdk.java.net/jdk/pull/1853



More information about the security-dev mailing list