diff options
| author | 2016-08-17 18:35:12 +0200 | |
|---|---|---|
| committer | 2016-08-17 18:35:12 +0200 | |
| commit | 5540c815de36e316d0749ce2163f12c61895b327 (patch) | |
| tree | 2b30d5ae98735ee7cba7d1c0087c51d68ed3ebf9 /src/main/java/cuchaz/enigma/Util.java | |
| parent | Revert "Removed util" (diff) | |
| download | enigma-fork-5540c815de36e316d0749ce2163f12c61895b327.tar.gz enigma-fork-5540c815de36e316d0749ce2163f12c61895b327.tar.xz enigma-fork-5540c815de36e316d0749ce2163f12c61895b327.zip | |
Revert "Removed unused methods"
This reverts commit 1742190f784d0d62e7cc869eebafdfe1927e448f.
Diffstat (limited to 'src/main/java/cuchaz/enigma/Util.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/Util.java | 31 |
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 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 { | |||
| 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 | } |