summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/Util.java
diff options
context:
space:
mode:
authorGravatar jeff2014-07-29 00:37:51 -0400
committerGravatar jeff2014-07-29 00:37:51 -0400
commit1318888e5b37a2d76270c5c330e63d4b5dcf779e (patch)
tree1a26f087424b310fa8c7bf06fcccfb1f92d5bdca /src/cuchaz/enigma/Util.java
parentadded identifier renaming capability (diff)
downloadenigma-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.java44
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 ******************************************************************************/
11package cuchaz.enigma; 11package cuchaz.enigma;
12 12
13import java.awt.Desktop;
13import java.io.Closeable; 14import java.io.Closeable;
14import java.io.IOException; 15import java.io.IOException;
16import java.io.InputStream;
17import java.io.InputStreamReader;
18import java.net.URI;
19import java.net.URISyntaxException;
15import java.util.jar.JarFile; 20import java.util.jar.JarFile;
16 21
22import com.google.common.io.CharStreams;
23
17 24
18public class Util 25public 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}