diff options
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/Util.java | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/src/main/java/cuchaz/enigma/Util.java b/src/main/java/cuchaz/enigma/Util.java deleted file mode 100644 index 9445b2b..0000000 --- a/src/main/java/cuchaz/enigma/Util.java +++ /dev/null | |||
| @@ -1,68 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import com.google.common.io.CharStreams; | ||
| 14 | |||
| 15 | import java.awt.Desktop; | ||
| 16 | import java.io.*; | ||
| 17 | import java.net.URI; | ||
| 18 | import java.net.URISyntaxException; | ||
| 19 | import java.util.Arrays; | ||
| 20 | import java.util.jar.JarFile; | ||
| 21 | |||
| 22 | import javassist.CannotCompileException; | ||
| 23 | import javassist.CtClass; | ||
| 24 | import javassist.bytecode.Descriptor; | ||
| 25 | |||
| 26 | public class Util { | ||
| 27 | |||
| 28 | public static int combineHashesOrdered(Object... objs) { | ||
| 29 | return combineHashesOrdered(Arrays.asList(objs)); | ||
| 30 | } | ||
| 31 | |||
| 32 | public static int combineHashesOrdered(Iterable<Object> objs) { | ||
| 33 | final int prime = 67; | ||
| 34 | int result = 1; | ||
| 35 | for (Object obj : objs) { | ||
| 36 | result *= prime; | ||
| 37 | if (obj != null) { | ||
| 38 | result += obj.hashCode(); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | return result; | ||
| 42 | } | ||
| 43 | |||
| 44 | public static String readStreamToString(InputStream in) throws IOException { | ||
| 45 | return CharStreams.toString(new InputStreamReader(in, "UTF-8")); | ||
| 46 | } | ||
| 47 | |||
| 48 | public static String readResourceToString(String path) throws IOException { | ||
| 49 | InputStream in = Util.class.getResourceAsStream(path); | ||
| 50 | if (in == null) { | ||
| 51 | throw new IllegalArgumentException("Resource not found! " + path); | ||
| 52 | } | ||
| 53 | return readStreamToString(in); | ||
| 54 | } | ||
| 55 | |||
| 56 | public static void openUrl(String url) { | ||
| 57 | if (Desktop.isDesktopSupported()) { | ||
| 58 | Desktop desktop = Desktop.getDesktop(); | ||
| 59 | try { | ||
| 60 | desktop.browse(new URI(url)); | ||
| 61 | } catch (IOException ex) { | ||
| 62 | throw new Error(ex); | ||
| 63 | } catch (URISyntaxException ex) { | ||
| 64 | throw new IllegalArgumentException(ex); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
| 68 | } | ||