diff options
| author | 2016-08-17 17:11:31 +0200 | |
|---|---|---|
| committer | 2016-08-17 17:11:31 +0200 | |
| commit | f73f5a47eb675be69cb6fac7327fe5bfcb52b16e (patch) | |
| tree | 2c9b4394323d1dd078887129914ec1d54fbc11bf /src/main/java | |
| parent | better fix for #2 (diff) | |
| download | enigma-f73f5a47eb675be69cb6fac7327fe5bfcb52b16e.tar.gz enigma-f73f5a47eb675be69cb6fac7327fe5bfcb52b16e.tar.xz enigma-f73f5a47eb675be69cb6fac7327fe5bfcb52b16e.zip | |
Revert "Removed util"
This reverts commit 648239667318a26169488274cf73662afd85d0a8.
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/Util.java | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/Util.java b/src/main/java/cuchaz/enigma/Util.java new file mode 100644 index 00000000..9445b2b4 --- /dev/null +++ b/src/main/java/cuchaz/enigma/Util.java | |||
| @@ -0,0 +1,68 @@ | |||
| 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 | } | ||