Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions spring-core/src/main/java/org/springframework/asm/ClassReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,21 @@ private static byte[] readStream(final InputStream inputStream, final boolean cl
if (inputStream == null) {
throw new IOException("Class not found");
}
int expectedLength = inputStream.available();
//some implementations can return 0 while holding available data
int bufferSize = expectedLength == 0
? INPUT_STREAM_DATA_CHUNK_SIZE
: expectedLength;
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
byte[] data = new byte[INPUT_STREAM_DATA_CHUNK_SIZE];
byte[] data = new byte[bufferSize];
int bytesRead;
while ((bytesRead = inputStream.read(data, 0, data.length)) != -1) {
int readCount = 0;
while ((bytesRead = inputStream.read(data, 0, bufferSize)) != -1) {
outputStream.write(data, 0, bytesRead);
readCount++;
}
outputStream.flush();
return outputStream.toByteArray();
return readCount == 1 ? data : outputStream.toByteArray();
} finally {
if (close) {
inputStream.close();
Expand Down