From 5540c815de36e316d0749ce2163f12c61895b327 Mon Sep 17 00:00:00 2001 From: asiekierka Date: Wed, 17 Aug 2016 18:35:12 +0200 Subject: Revert "Removed unused methods" This reverts commit 1742190f784d0d62e7cc869eebafdfe1927e448f. --- src/main/java/cuchaz/enigma/Util.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/main/java/cuchaz/enigma/Util.java') diff --git a/src/main/java/cuchaz/enigma/Util.java b/src/main/java/cuchaz/enigma/Util.java index 9445b2b..1bcdb9e 100644 --- a/src/main/java/cuchaz/enigma/Util.java +++ b/src/main/java/cuchaz/enigma/Util.java @@ -41,6 +41,27 @@ public class Util { return result; } + public static void closeQuietly(Closeable closeable) { + if (closeable != null) { + try { + closeable.close(); + } catch (IOException ex) { + // just ignore any further exceptions + } + } + } + + public static void closeQuietly(JarFile jarFile) { + // silly library should implement Closeable... + if (jarFile != null) { + try { + jarFile.close(); + } catch (IOException ex) { + // just ignore any further exceptions + } + } + } + public static String readStreamToString(InputStream in) throws IOException { return CharStreams.toString(new InputStreamReader(in, "UTF-8")); } @@ -65,4 +86,14 @@ public class Util { } } } + + public static void writeClass(CtClass c) { + String name = Descriptor.toJavaName(c.getName()); + File file = new File(name + ".class"); + try (FileOutputStream out = new FileOutputStream(file)) { + out.write(c.toBytecode()); + } catch (IOException | CannotCompileException ex) { + throw new Error(ex); + } + } } -- cgit v1.2.3