summaryrefslogtreecommitdiffstats
path: root/src/org/jetbrains/java/decompiler/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/jetbrains/java/decompiler/util')
-rw-r--r--src/org/jetbrains/java/decompiler/util/DataInputFullStream.java6
-rw-r--r--src/org/jetbrains/java/decompiler/util/InterpreterUtil.java25
2 files changed, 28 insertions, 3 deletions
diff --git a/src/org/jetbrains/java/decompiler/util/DataInputFullStream.java b/src/org/jetbrains/java/decompiler/util/DataInputFullStream.java
index 79e8c1d..011edde 100644
--- a/src/org/jetbrains/java/decompiler/util/DataInputFullStream.java
+++ b/src/org/jetbrains/java/decompiler/util/DataInputFullStream.java
@@ -15,14 +15,14 @@
*/
package org.jetbrains.java.decompiler.util;
+import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
-import java.io.InputStream;
public class DataInputFullStream extends DataInputStream {
- public DataInputFullStream(InputStream in) {
- super(in);
+ public DataInputFullStream(byte[] bytes) {
+ super(new ByteArrayInputStream(bytes));
}
public int readFull(byte[] b) throws IOException {
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);