From 1318888e5b37a2d76270c5c330e63d4b5dcf779e Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 29 Jul 2014 00:37:51 -0400 Subject: added start of menu bar added about bow --- src/cuchaz/enigma/Util.java | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/cuchaz/enigma/Util.java') 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 @@ ******************************************************************************/ package cuchaz.enigma; +import java.awt.Desktop; import java.io.Closeable; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URI; +import java.net.URISyntaxException; import java.util.jar.JarFile; +import com.google.common.io.CharStreams; + public class Util { @@ -62,4 +69,41 @@ public class Util } } } + + public static String readStreamToString( InputStream in ) + throws IOException + { + return CharStreams.toString( new InputStreamReader( in, "UTF-8" ) ); + } + + public static String readResourceToString( String path ) + throws IOException + { + InputStream in = Util.class.getResourceAsStream( path ); + if( in == null ) + { + throw new IllegalArgumentException( "Resource not found! " + path ); + } + return readStreamToString( in ); + } + + public static void openUrl( String url ) + { + if( Desktop.isDesktopSupported() ) + { + Desktop desktop = Desktop.getDesktop(); + try + { + desktop.browse( new URI( url ) ); + } + catch( IOException ex ) + { + throw new Error( ex ); + } + catch( URISyntaxException ex ) + { + throw new IllegalArgumentException( ex ); + } + } + } } -- cgit v1.2.3