mirror of
https://github.com/moparisthebest/fernflower
synced 2025-01-06 19:28:00 -05:00
IDEA-130478 (optimization of 6fcac6a5: less short-lived objects)
This commit is contained in:
parent
4638144fad
commit
5349ad435b
@ -62,29 +62,27 @@ public class InterpreterUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] getBytes(ZipFile archive, ZipEntry entry) throws IOException {
|
public static byte[] getBytes(ZipFile archive, ZipEntry entry) throws IOException {
|
||||||
return readAndClose(archive.getInputStream(entry), entry.getSize());
|
return readAndClose(archive.getInputStream(entry), (int)entry.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] getBytes(File file) throws IOException {
|
public static byte[] getBytes(File file) throws IOException {
|
||||||
return readAndClose(new FileInputStream(file), file.length());
|
return readAndClose(new FileInputStream(file), (int)file.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] readAndClose(InputStream stream, long length) throws IOException {
|
private static byte[] readAndClose(InputStream stream, int length) throws IOException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
byte[] bytes = new byte[(int) length];
|
byte[] bytes = new byte[length];
|
||||||
DataInputStream dataStream = new DataInputStream(stream);
|
int n = 0, off = 0;
|
||||||
|
while (n < length) {
|
||||||
try {
|
int count = stream.read(bytes, off + n, length - n);
|
||||||
dataStream.readFully(bytes);
|
if (count < 0) {
|
||||||
} catch (EOFException ex) {
|
throw new IOException("premature end of stream");
|
||||||
throw new IOException("premature end of stream", ex);
|
}
|
||||||
} finally {
|
n += count;
|
||||||
dataStream.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
} finally {
|
}
|
||||||
|
finally {
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user