Skip to content

Commit

Permalink
HHH-16965 ByteCodeHelper test utility might occasionally not read the…
Browse files Browse the repository at this point in the history
… full bytestream
  • Loading branch information
Sanne committed Aug 1, 2023
1 parent ebab541 commit 9e24945
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

import org.hibernate.internal.util.collections.ArrayHelper;

Expand Down Expand Up @@ -39,29 +40,19 @@ public static byte[] readByteCode(InputStream inputStream) throws IOException {
throw new IOException( "null input stream" );
}

final byte[] buffer = new byte[409600];
final byte[] buffer = new byte[8_000]; //reasonably large enough for most classes
byte[] classBytes = ArrayHelper.EMPTY_BYTE_ARRAY;

try {
int r = inputStream.read( buffer );
while ( r >= buffer.length ) {
final byte[] temp = new byte[ classBytes.length + buffer.length ];
// copy any previously read bytes into the temp array
System.arraycopy( classBytes, 0, temp, 0, classBytes.length );
while ( r != -1 ) {
final byte[] temp = Arrays.copyOf( classBytes, classBytes.length + r );
// copy the just read bytes into the temp array (after the previously read)
System.arraycopy( buffer, 0, temp, classBytes.length, buffer.length );
System.arraycopy( buffer, 0, temp, classBytes.length, r );
classBytes = temp;
// read the next set of bytes into buffer
r = inputStream.read( buffer );
}
if ( r != -1 ) {
final byte[] temp = new byte[ classBytes.length + r ];
// copy any previously read bytes into the temp array
System.arraycopy( classBytes, 0, temp, 0, classBytes.length );
// copy the just read bytes into the temp array (after the previously read)
System.arraycopy( buffer, 0, temp, classBytes.length, r );
classBytes = temp;
}
}
finally {
try {
Expand Down

0 comments on commit 9e24945

Please sign in to comment.