提交 0889428f 编写于 作者: A andrew

8138978: Examine usages of sun.misc.IOUtils

Reviewed-by: mbalao
上级 149b89c9
......@@ -47,8 +47,6 @@ import javax.naming.ldap.Control;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocket;
import sun.misc.IOUtils;
/**
* A thread that creates a connection to an LDAP server.
* After the connection, the thread reads from the connection.
......@@ -886,7 +884,7 @@ public final class Connection implements Runnable {
}
// read in seqlen bytes
byte[] left = IOUtils.readFully(in, seqlen, false);
byte[] left = readFully(in, seqlen);
inbuf = Arrays.copyOf(inbuf, offset + left.length);
System.arraycopy(left, 0, inbuf, offset, left.length);
offset += left.length;
......@@ -981,6 +979,31 @@ System.err.println("bytesread: " + bytesread);
}
}
private static byte[] readFully(InputStream is, int length)
throws IOException
{
byte[] buf = new byte[Math.min(length, 8192)];
int nread = 0;
while (nread < length) {
int bytesToRead;
if (nread >= buf.length) { // need to allocate a larger buffer
bytesToRead = Math.min(length - nread, buf.length + 8192);
if (buf.length < nread + bytesToRead) {
buf = Arrays.copyOf(buf, nread + bytesToRead);
}
} else {
bytesToRead = buf.length - nread;
}
int count = is.read(buf, nread, bytesToRead);
if (count < 0) {
if (buf.length != nread)
buf = Arrays.copyOf(buf, nread);
break;
}
nread += count;
}
return buf;
}
// This code must be uncommented to run the LdapAbandonTest.
/*public void sendSearchReqs(String dn, int numReqs) {
......
......@@ -422,7 +422,12 @@ class JarFile extends ZipFile {
*/
private byte[] getBytes(ZipEntry ze) throws IOException {
try (InputStream is = super.getInputStream(ze)) {
return IOUtils.readFully(is, (int)ze.getSize(), true);
int len = (int)ze.getSize();
byte[] b = IOUtils.readAllBytes(is);
if (len != -1 && b.length != len)
throw new EOFException("Expected:" + len + ", read:" + b.length);
return b;
}
}
......
......@@ -33,6 +33,7 @@ import java.net.URLConnection;
import java.net.MalformedURLException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.io.EOFException;
import java.io.File;
import java.io.FilePermission;
import java.io.IOException;
......@@ -333,7 +334,9 @@ public class AppletClassLoader extends URLClassLoader {
byte[] b;
try {
b = IOUtils.readFully(in, len, true);
b = IOUtils.readAllBytes(in);
if (len != -1 && b.length != len)
throw new EOFException("Expected:" + len + ", read:" + b.length);
} finally {
in.close();
}
......
......@@ -25,6 +25,7 @@
package sun.reflect.misc;
import java.io.EOFException;
import java.security.AllPermission;
import java.security.AccessController;
import java.security.PermissionCollection;
......@@ -42,8 +43,8 @@ import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
import sun.misc.IOUtils;
import sun.misc.IOUtils;
class Trampoline {
static {
......@@ -382,15 +383,12 @@ public final class MethodUtil extends SecureClassLoader {
}
}
int len = uc.getContentLength();
InputStream in = new BufferedInputStream(uc.getInputStream());
byte[] b;
try {
b = IOUtils.readFully(in, len, true);
} finally {
in.close();
try (InputStream in = new BufferedInputStream(uc.getInputStream())) {
byte[] b = IOUtils.readAllBytes(in);
if (len != -1 && b.length != len)
throw new EOFException("Expected:" + len + ", read:" + b.length);
return b;
}
return b;
}
......
......@@ -27,6 +27,7 @@ package sun.security.timestamp;
import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
......@@ -147,8 +148,11 @@ public class HttpTimestamper implements Timestamper {
}
verifyMimeType(connection.getContentType());
int contentLength = connection.getContentLength();
replyBuffer = IOUtils.readFully(input, contentLength, false);
int clen = connection.getContentLength();
replyBuffer = IOUtils.readAllBytes(input);
if (clen != -1 && replyBuffer.length != clen)
throw new EOFException("Expected:" + clen +
", read:" + replyBuffer.length);
if (debug != null) {
debug.println("received timestamp response (length=" +
......
......@@ -743,7 +743,7 @@ public class TimestampCheck {
try (JarFile jf = new JarFile(file)) {
JarEntry je = jf.getJarEntry("META-INF/SIGNER.RSA");
try (InputStream is = jf.getInputStream(je)) {
byte[] content = IOUtils.readFully(is, -1, true);
byte[] content = IOUtils.readAllBytes(is);
PKCS7 p7 = new PKCS7(content);
SignerInfo[] si = p7.getSignerInfos();
if (si == null || si.length == 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册