Commit cf523596 authored by Eric Bruneton's avatar Eric Bruneton

Fix readStream on empty streams, make the previously added test pass. Also fix...

Fix readStream on empty streams, make the previously added test pass. Also fix the same issue in AsmTest.
parent 74c2c219
Pipeline #1029 passed with stage
in 6 minutes and 14 seconds
......@@ -85,6 +85,10 @@ import java.util.stream.Stream;
*/
public abstract class AsmTest {
/** The size of the temporary byte array used to read class input streams chunk by chunk. */
private static final int INPUT_STREAM_DATA_CHUNK_SIZE = 4096;
/** The name of JDK9 module classes. */
private static final String MODULE_INFO = "module-info";
/**
......@@ -436,7 +440,7 @@ public abstract class AsmTest {
try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(resourceName)) {
assertNotNull(inputStream, "Class not found " + name);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] data = new byte[inputStream.available()];
byte[] data = new byte[INPUT_STREAM_DATA_CHUNK_SIZE];
int bytesRead;
while ((bytesRead = inputStream.read(data, 0, data.length)) != -1) {
outputStream.write(data, 0, bytesRead);
......
......@@ -87,6 +87,9 @@ public class ClassReader {
*/
static final int EXPAND_ASM_INSNS = 256;
/** The size of the temporary byte array used to read class input streams chunk by chunk. */
private static final int INPUT_STREAM_DATA_CHUNK_SIZE = 4096;
/**
* A byte array containing the JVMS ClassFile structure to be parsed. <i>The content of this array
* must not be modified. This field is intended for {@link Attribute} sub classes, and is normally
......@@ -262,7 +265,7 @@ public class ClassReader {
}
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] data = new byte[inputStream.available()];
byte[] data = new byte[INPUT_STREAM_DATA_CHUNK_SIZE];
int bytesRead;
while ((bytesRead = inputStream.read(data, 0, data.length)) != -1) {
outputStream.write(data, 0, bytesRead);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment