summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/Util.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/Util.java')
-rw-r--r--src/main/java/cuchaz/enigma/Util.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/Util.java b/src/main/java/cuchaz/enigma/Util.java
index 9445b2b4..1bcdb9ea 100644
--- a/src/main/java/cuchaz/enigma/Util.java
+++ b/src/main/java/cuchaz/enigma/Util.java
@@ -41,6 +41,27 @@ public class Util {
41 return result; 41 return result;
42 } 42 }
43 43
44 public static void closeQuietly(Closeable closeable) {
45 if (closeable != null) {
46 try {
47 closeable.close();
48 } catch (IOException ex) {
49 // just ignore any further exceptions
50 }
51 }
52 }
53
54 public static void closeQuietly(JarFile jarFile) {
55 // silly library should implement Closeable...
56 if (jarFile != null) {
57 try {
58 jarFile.close();
59 } catch (IOException ex) {
60 // just ignore any further exceptions
61 }
62 }
63 }
64
44 public static String readStreamToString(InputStream in) throws IOException { 65 public static String readStreamToString(InputStream in) throws IOException {
45 return CharStreams.toString(new InputStreamReader(in, "UTF-8")); 66 return CharStreams.toString(new InputStreamReader(in, "UTF-8"));
46 } 67 }
@@ -65,4 +86,14 @@ public class Util {
65 } 86 }
66 } 87 }
67 } 88 }
89
90 public static void writeClass(CtClass c) {
91 String name = Descriptor.toJavaName(c.getName());
92 File file = new File(name + ".class");
93 try (FileOutputStream out = new FileOutputStream(file)) {
94 out.write(c.toBytecode());
95 } catch (IOException | CannotCompileException ex) {
96 throw new Error(ex);
97 }
98 }
68} 99}