提交 ab3130ac 编写于 作者: S shurailine

8039438: Some tests depend on internal API sun.misc.IOUtils

Summary: Remove dependency on sun.misc.IOUtils.readFully(InputStream, int, boolean)
Reviewed-by: alanb, mchung, chegar
Contributed-by: NAlexandre Iline <alexandre.iline@oracle.com>
上级 0889428f
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,15 +25,18 @@ ...@@ -25,15 +25,18 @@
* @test * @test
* @summary Test consistent parsing of ex-RUNTIME annotations that * @summary Test consistent parsing of ex-RUNTIME annotations that
* were changed and separately compiled to have CLASS retention * were changed and separately compiled to have CLASS retention
* @library /lib/testlibrary
* @build jdk.testlibrary.IOUtils
* @run main AnnotationTypeRuntimeAssumptionTest
*/ */
import sun.misc.IOUtils;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import jdk.testlibrary.IOUtils;
import static java.lang.annotation.RetentionPolicy.CLASS; import static java.lang.annotation.RetentionPolicy.CLASS;
import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.RetentionPolicy.RUNTIME;
...@@ -137,7 +140,7 @@ public class AnnotationTypeRuntimeAssumptionTest { ...@@ -137,7 +140,7 @@ public class AnnotationTypeRuntimeAssumptionTest {
String altPath = altName.replace('.', '/').concat(".class"); String altPath = altName.replace('.', '/').concat(".class");
try (InputStream is = getResourceAsStream(altPath)) { try (InputStream is = getResourceAsStream(altPath)) {
if (is != null) { if (is != null) {
byte[] bytes = IOUtils.readFully(is, -1, true); byte[] bytes = IOUtils.readFully(is);
// patch class bytes to contain original name // patch class bytes to contain original name
for (int i = 0; i < bytes.length - 2; i++) { for (int i = 0; i < bytes.length - 2; i++) {
if (bytes[i] == '_' && if (bytes[i] == '_' &&
...@@ -160,7 +163,7 @@ public class AnnotationTypeRuntimeAssumptionTest { ...@@ -160,7 +163,7 @@ public class AnnotationTypeRuntimeAssumptionTest {
String path = name.replace('.', '/').concat(".class"); String path = name.replace('.', '/').concat(".class");
try (InputStream is = getResourceAsStream(path)) { try (InputStream is = getResourceAsStream(path)) {
if (is != null) { if (is != null) {
byte[] bytes = IOUtils.readFully(is, -1, true); byte[] bytes = IOUtils.readFully(is);
return defineClass(name, bytes, 0, bytes.length); return defineClass(name, bytes, 0, bytes.length);
} }
else { else {
......
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -22,11 +22,14 @@ ...@@ -22,11 +22,14 @@
*/ */
/* /*
@test * @test
@bug 8004970 * @bug 8004970
@summary Lambda serialization in the presence of class loaders * @summary Lambda serialization in the presence of class loaders
@author Peter Levart * @library /lib/testlibrary
*/ * @build jdk.testlibrary.IOUtils
* @run main LambdaClassLoaderSerialization
* @author Peter Levart
*/
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
...@@ -37,6 +40,8 @@ import java.io.ObjectOutputStream; ...@@ -37,6 +40,8 @@ import java.io.ObjectOutputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import jdk.testlibrary.IOUtils;
public class LambdaClassLoaderSerialization { public class LambdaClassLoaderSerialization {
public interface SerializableRunnable extends Runnable, Serializable {} public interface SerializableRunnable extends Runnable, Serializable {}
...@@ -125,7 +130,7 @@ public class LambdaClassLoaderSerialization { ...@@ -125,7 +130,7 @@ public class LambdaClassLoaderSerialization {
String path = name.replace('.', '/').concat(".class"); String path = name.replace('.', '/').concat(".class");
try (InputStream is = getResourceAsStream(path)) { try (InputStream is = getResourceAsStream(path)) {
if (is != null) { if (is != null) {
byte[] bytes = readFully(is); byte[] bytes = IOUtils.readFully(is);
return defineClass(name, bytes, 0, bytes.length); return defineClass(name, bytes, 0, bytes.length);
} else { } else {
throw new ClassNotFoundException(name); throw new ClassNotFoundException(name);
...@@ -135,30 +140,5 @@ public class LambdaClassLoaderSerialization { ...@@ -135,30 +140,5 @@ public class LambdaClassLoaderSerialization {
throw new ClassNotFoundException(name, e); throw new ClassNotFoundException(name, e);
} }
} }
static byte[] readFully(InputStream is) throws IOException {
byte[] output = {};
int pos = 0;
while (true) {
int bytesToRead;
if (pos >= output.length) { // Only expand when there's no room
bytesToRead = output.length + 1024;
if (output.length < pos + bytesToRead) {
output = Arrays.copyOf(output, pos + bytesToRead);
}
} else {
bytesToRead = output.length - pos;
}
int cc = is.read(output, pos, bytesToRead);
if (cc < 0) {
if (output.length != pos) {
output = Arrays.copyOf(output, pos);
}
break;
}
pos += cc;
}
return output;
}
} }
} }
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
* @summary Test that a static method on an interface doesn't hide a default * @summary Test that a static method on an interface doesn't hide a default
* method with the same name and signature in a separate compilation * method with the same name and signature in a separate compilation
* scenario. * scenario.
* @library /lib/testlibrary
* @build jdk.testlibrary.IOUtils
* @run main StaticInterfaceMethodInWayOfDefault
*/ */
import java.io.IOException; import java.io.IOException;
...@@ -35,7 +38,7 @@ import java.lang.reflect.InvocationTargetException; ...@@ -35,7 +38,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import sun.misc.IOUtils; import jdk.testlibrary.IOUtils;
public class StaticInterfaceMethodInWayOfDefault { public class StaticInterfaceMethodInWayOfDefault {
public interface A_v1 { public interface A_v1 {
...@@ -144,7 +147,7 @@ public class StaticInterfaceMethodInWayOfDefault { ...@@ -144,7 +147,7 @@ public class StaticInterfaceMethodInWayOfDefault {
String altPath = altName.replace('.', '/').concat(".class"); String altPath = altName.replace('.', '/').concat(".class");
try (InputStream is = getResourceAsStream(altPath)) { try (InputStream is = getResourceAsStream(altPath)) {
if (is != null) { if (is != null) {
byte[] bytes = IOUtils.readFully(is, -1, true); byte[] bytes = IOUtils.readFully(is);
// patch class bytes to contain original name // patch class bytes to contain original name
for (int i = 0; i < bytes.length - 2; i++) { for (int i = 0; i < bytes.length - 2; i++) {
if (bytes[i] == '_' && if (bytes[i] == '_' &&
...@@ -167,7 +170,7 @@ public class StaticInterfaceMethodInWayOfDefault { ...@@ -167,7 +170,7 @@ public class StaticInterfaceMethodInWayOfDefault {
String path = name.replace('.', '/').concat(".class"); String path = name.replace('.', '/').concat(".class");
try (InputStream is = getResourceAsStream(path)) { try (InputStream is = getResourceAsStream(path)) {
if (is != null) { if (is != null) {
byte[] bytes = IOUtils.readFully(is, -1, true); byte[] bytes = IOUtils.readFully(is);
return defineClass(name, bytes, 0, bytes.length); return defineClass(name, bytes, 0, bytes.length);
} }
else { else {
......
...@@ -228,4 +228,3 @@ public final class FileUtils { ...@@ -228,4 +228,3 @@ public final class FileUtils {
return areFileSystemsAccessible; return areFileSystemsAccessible;
} }
} }
/*
* Copyright (c) 2014, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.testlibrary;
/**
* Defines useful I/O methods.
*/
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
public final class IOUtils {
/*
* Prevent instantiation.
*/
private IOUtils() {}
/**
* Read all bytes from <code>in</code>
* until EOF is detected.
* @param in input stream, must not be null
* @return bytes read
* @throws IOException Any IO error.
*/
public static byte[] readFully(InputStream is) throws IOException {
byte[] output = {};
int pos = 0;
while (true) {
int bytesToRead;
if (pos >= output.length) { // Only expand when there's no room
bytesToRead = output.length + 1024;
if (output.length < pos + bytesToRead) {
output = Arrays.copyOf(output, pos + bytesToRead);
}
} else {
bytesToRead = output.length - pos;
}
int cc = is.read(output, pos, bytesToRead);
if (cc < 0) {
if (output.length != pos) {
output = Arrays.copyOf(output, pos);
}
break;
}
pos += cc;
}
return output;
}
}
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
* @test * @test
* @bug 8031572 * @bug 8031572
* @summary jarsigner -verify exits with 0 when a jar file is not properly signed * @summary jarsigner -verify exits with 0 when a jar file is not properly signed
* @library /lib/testlibrary
* @build jdk.testlibrary.IOUtils
* @run main EntriesOrder
*/ */
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -39,6 +42,8 @@ import java.util.jar.JarInputStream; ...@@ -39,6 +42,8 @@ import java.util.jar.JarInputStream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import jdk.testlibrary.IOUtils;
public class EntriesOrder { public class EntriesOrder {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
...@@ -106,7 +111,7 @@ public class EntriesOrder { ...@@ -106,7 +111,7 @@ public class EntriesOrder {
Enumeration<JarEntry> jes = jf.entries(); Enumeration<JarEntry> jes = jf.entries();
while (jes.hasMoreElements()) { while (jes.hasMoreElements()) {
JarEntry je = jes.nextElement(); JarEntry je = jes.nextElement();
sun.misc.IOUtils.readFully(jf.getInputStream(je), -1, true); IOUtils.readFully(jf.getInputStream(je));
Certificate[] certs = je.getCertificates(); Certificate[] certs = je.getCertificates();
if (certs != null && certs.length > 0) { if (certs != null && certs.length > 0) {
cc++; cc++;
...@@ -138,7 +143,7 @@ public class EntriesOrder { ...@@ -138,7 +143,7 @@ public class EntriesOrder {
while (true) { while (true) {
JarEntry je = jis.getNextJarEntry(); JarEntry je = jis.getNextJarEntry();
if (je == null) break; if (je == null) break;
sun.misc.IOUtils.readFully(jis, -1, true); IOUtils.readFully(jis);
Certificate[] certs = je.getCertificates(); Certificate[] certs = je.getCertificates();
if (certs != null && certs.length > 0) { if (certs != null && certs.length > 0) {
cc++; cc++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册