8289659: Refactor I/O stream copying to use InputStream.readAllBytes in X509CertPath
Reviewed-by: attila, weijun
This commit is contained in:
parent
1e270ea4f5
commit
0ca74f538e
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2022, 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
|
||||
@ -26,7 +26,6 @@
|
||||
package sun.security.provider.certpath;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
@ -185,7 +184,7 @@ public class X509CertPath extends CertPath {
|
||||
}
|
||||
|
||||
try {
|
||||
DerInputStream dis = new DerInputStream(readAllBytes(is));
|
||||
DerInputStream dis = new DerInputStream(is.readAllBytes());
|
||||
DerValue[] seq = dis.getSequence(3);
|
||||
if (seq.length == 0) {
|
||||
return Collections.<X509Certificate>emptyList();
|
||||
@ -228,7 +227,7 @@ public class X509CertPath extends CertPath {
|
||||
if (is.markSupported() == false) {
|
||||
// Copy the entire input stream into an InputStream that does
|
||||
// support mark
|
||||
is = new ByteArrayInputStream(readAllBytes(is));
|
||||
is = new ByteArrayInputStream(is.readAllBytes());
|
||||
}
|
||||
PKCS7 pkcs7 = new PKCS7(is);
|
||||
|
||||
@ -251,22 +250,6 @@ public class X509CertPath extends CertPath {
|
||||
return Collections.unmodifiableList(certList);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads the entire contents of an InputStream into a byte array.
|
||||
*
|
||||
* @param is the InputStream to read from
|
||||
* @return the bytes read from the InputStream
|
||||
*/
|
||||
private static byte[] readAllBytes(InputStream is) throws IOException {
|
||||
byte[] buffer = new byte[8192];
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
|
||||
int n;
|
||||
while ((n = is.read(buffer)) != -1) {
|
||||
baos.write(buffer, 0, n);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the encoded form of this certification path, using the
|
||||
* default encoding.
|
||||
|
Loading…
x
Reference in New Issue
Block a user