summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>2014-09-29 13:15:57 +0200
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>2014-09-29 13:15:57 +0200
commit5349ad435b3659f2e58fec2a04d0e581456f2351 (patch)
tree674ca9a01e7c6ae0e10d8a1361cdacb916b4d9c8
parent4638144fad4a887058c81eea058836372380de0c (diff)
downloadfernflower-5349ad435b3659f2e58fec2a04d0e581456f2351.tar
fernflower-5349ad435b3659f2e58fec2a04d0e581456f2351.tar.gz
fernflower-5349ad435b3659f2e58fec2a04d0e581456f2351.tar.lz
fernflower-5349ad435b3659f2e58fec2a04d0e581456f2351.tar.xz
fernflower-5349ad435b3659f2e58fec2a04d0e581456f2351.zip
IDEA-130478 (optimization of 6fcac6a5: less short-lived objects)
-rw-r--r--src/org/jetbrains/java/decompiler/util/InterpreterUtil.java28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java b/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java
index 0644b69..dfd8b75 100644
--- a/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java
+++ b/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java
@@ -62,29 +62,27 @@ public class InterpreterUtil {
}
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 {
- 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 {
- byte[] bytes = new byte[(int) length];
- DataInputStream dataStream = new DataInputStream(stream);
-
- try {
- dataStream.readFully(bytes);
- } catch (EOFException ex) {
- throw new IOException("premature end of stream", ex);
- } finally {
- dataStream.close();
+ byte[] bytes = new byte[length];
+ int n = 0, off = 0;
+ while (n < length) {
+ int count = stream.read(bytes, off + n, length - n);
+ if (count < 0) {
+ throw new IOException("premature end of stream");
+ }
+ n += count;
}
-
return bytes;
- } finally {
+ }
+ finally {
stream.close();
}
}