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

Reviewed-by: mcimadamore, alanb
This commit is contained in:
Andrey Turbanov 2021-03-16 10:10:05 +00:00 committed by Julia Boes
parent a31a23d5e7
commit 68deb24b38
7 changed files with 27 additions and 102 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -90,7 +90,7 @@ public class JarInputStream extends ZipInputStream {
{
if (e != null && JarFile.MANIFEST_NAME.equalsIgnoreCase(e.getName())) {
man = new Manifest();
byte bytes[] = getBytes(new BufferedInputStream(this));
byte[] bytes = readAllBytes();
man.read(new ByteArrayInputStream(bytes));
closeEntry();
if (doVerify) {
@ -102,18 +102,6 @@ public class JarInputStream extends ZipInputStream {
return e;
}
private byte[] getBytes(InputStream is)
throws IOException
{
byte[] buffer = new byte[8192];
ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
int n;
while ((n = is.read(buffer, 0, buffer.length)) != -1) {
baos.write(buffer, 0, n);
}
return baos.toByteArray();
}
/**
* Returns the {@code Manifest} for this JAR file, or
* {@code null} if none.