diff options
| author | 2014-07-29 00:37:51 -0400 | |
|---|---|---|
| committer | 2014-07-29 00:37:51 -0400 | |
| commit | 1318888e5b37a2d76270c5c330e63d4b5dcf779e (patch) | |
| tree | 1a26f087424b310fa8c7bf06fcccfb1f92d5bdca /src/cuchaz/enigma/Util.java | |
| parent | added identifier renaming capability (diff) | |
| download | enigma-fork-1318888e5b37a2d76270c5c330e63d4b5dcf779e.tar.gz enigma-fork-1318888e5b37a2d76270c5c330e63d4b5dcf779e.tar.xz enigma-fork-1318888e5b37a2d76270c5c330e63d4b5dcf779e.zip | |
added start of menu bar
added about bow
Diffstat (limited to 'src/cuchaz/enigma/Util.java')
| -rw-r--r-- | src/cuchaz/enigma/Util.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/Util.java b/src/cuchaz/enigma/Util.java index c51eb62..84927fd 100644 --- a/src/cuchaz/enigma/Util.java +++ b/src/cuchaz/enigma/Util.java | |||
| @@ -10,10 +10,17 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma; | 11 | package cuchaz.enigma; |
| 12 | 12 | ||
| 13 | import java.awt.Desktop; | ||
| 13 | import java.io.Closeable; | 14 | import java.io.Closeable; |
| 14 | import java.io.IOException; | 15 | import java.io.IOException; |
| 16 | import java.io.InputStream; | ||
| 17 | import java.io.InputStreamReader; | ||
| 18 | import java.net.URI; | ||
| 19 | import java.net.URISyntaxException; | ||
| 15 | import java.util.jar.JarFile; | 20 | import java.util.jar.JarFile; |
| 16 | 21 | ||
| 22 | import com.google.common.io.CharStreams; | ||
| 23 | |||
| 17 | 24 | ||
| 18 | public class Util | 25 | public class Util |
| 19 | { | 26 | { |
| @@ -62,4 +69,41 @@ public class Util | |||
| 62 | } | 69 | } |
| 63 | } | 70 | } |
| 64 | } | 71 | } |
| 72 | |||
| 73 | public static String readStreamToString( InputStream in ) | ||
| 74 | throws IOException | ||
| 75 | { | ||
| 76 | return CharStreams.toString( new InputStreamReader( in, "UTF-8" ) ); | ||
| 77 | } | ||
| 78 | |||
| 79 | public static String readResourceToString( String path ) | ||
| 80 | throws IOException | ||
| 81 | { | ||
| 82 | InputStream in = Util.class.getResourceAsStream( path ); | ||
| 83 | if( in == null ) | ||
| 84 | { | ||
| 85 | throw new IllegalArgumentException( "Resource not found! " + path ); | ||
| 86 | } | ||
| 87 | return readStreamToString( in ); | ||
| 88 | } | ||
| 89 | |||
| 90 | public static void openUrl( String url ) | ||
| 91 | { | ||
| 92 | if( Desktop.isDesktopSupported() ) | ||
| 93 | { | ||
| 94 | Desktop desktop = Desktop.getDesktop(); | ||
| 95 | try | ||
| 96 | { | ||
| 97 | desktop.browse( new URI( url ) ); | ||
| 98 | } | ||
| 99 | catch( IOException ex ) | ||
| 100 | { | ||
| 101 | throw new Error( ex ); | ||
| 102 | } | ||
| 103 | catch( URISyntaxException ex ) | ||
| 104 | { | ||
| 105 | throw new IllegalArgumentException( ex ); | ||
| 106 | } | ||
| 107 | } | ||
| 108 | } | ||
| 65 | } | 109 | } |