Fixing migration errors: stream.read() doesn't read the entire available stream. It has to be called in a loop or replaced with readFully().

This commit is contained in:
Stiver 2014-09-28 09:00:31 +02:00
parent a4054817d2
commit f875d27e6e

View File

@ -70,14 +70,21 @@ public class InterpreterUtil {
}
private static byte[] readAndClose(InputStream stream, long length) throws IOException {
try {
byte[] bytes = new byte[(int) length];
if (stream.read(bytes) != length) {
throw new IOException("premature end of stream");
DataInputStream dataStream = new DataInputStream(stream);
try {
dataStream.readFully(bytes);
} catch (EOFException ex) {
throw new IOException("premature end of stream", ex);
} finally {
dataStream.close();
}
return bytes;
}
finally {
} finally {
stream.close();
}
}