summaryrefslogtreecommitdiffstats
path: root/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java
diff options
context:
space:
mode:
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>2014-09-05 13:12:40 +0400
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>2014-09-07 14:35:39 +0400
commitff382a6fdfec77d9b9cb3165eb7eb2989abb604f (patch)
treece347d64ee9dd061d7bb3cd7a530650ccb6448d3 /src/org/jetbrains/java/decompiler/util/InterpreterUtil.java
parent4e79d160ca382125d76bab3f1d18414d6308d614 (diff)
downloadfernflower-ff382a6fdfec77d9b9cb3165eb7eb2989abb604f.tar
fernflower-ff382a6fdfec77d9b9cb3165eb7eb2989abb604f.tar.gz
fernflower-ff382a6fdfec77d9b9cb3165eb7eb2989abb604f.tar.lz
fernflower-ff382a6fdfec77d9b9cb3165eb7eb2989abb604f.tar.xz
fernflower-ff382a6fdfec77d9b9cb3165eb7eb2989abb604f.zip
java-decompiler: fixes and cleanups
- console decompiler: resource closing, lookup instead of scan, error reporting - logger interface reworked - saver interface renamed - bytecode provider returns byte array (to reduce stream leakage) - extra level of context unit avoided - unneeded exceptions, dead code, formatting
Diffstat (limited to 'src/org/jetbrains/java/decompiler/util/InterpreterUtil.java')
-rw-r--r--src/org/jetbrains/java/decompiler/util/InterpreterUtil.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java b/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java
index 5f48e32..0047bb7 100644
--- a/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java
+++ b/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java
@@ -23,6 +23,8 @@ import java.nio.channels.FileChannel;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
public class InterpreterUtil {
public static final boolean IS_WINDOWS = System.getProperty("os.name", "").startsWith("Windows");
@@ -59,13 +61,36 @@ public class InterpreterUtil {
}
}
+ public static byte[] getBytes(ZipFile archive, ZipEntry entry) throws IOException {
+ return readAndClose(archive.getInputStream(entry), entry.getSize());
+ }
+
+ public static byte[] getBytes(File file) throws IOException {
+ return readAndClose(new FileInputStream(file), file.length());
+ }
+
+ 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");
+ }
+ return bytes;
+ }
+ finally {
+ stream.close();
+ }
+ }
+
public static String getIndentString(int length) {
+ if (length == 0) return "";
StringBuilder buf = new StringBuilder();
appendIndent(buf, length);
return buf.toString();
}
public static void appendIndent(StringBuilder buffer, int length) {
+ if (length == 0) return;
String indent = (String)DecompilerContext.getProperty(IFernflowerPreferences.INDENT_STRING);
while (length-- > 0) {
buffer.append(indent);