summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar asiekierka2016-08-17 17:11:31 +0200
committerGravatar asiekierka2016-08-17 17:11:31 +0200
commitf73f5a47eb675be69cb6fac7327fe5bfcb52b16e (patch)
tree2c9b4394323d1dd078887129914ec1d54fbc11bf /src/main/java
parentbetter fix for #2 (diff)
downloadenigma-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.java68
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 ******************************************************************************/
11package cuchaz.enigma;
12
13import com.google.common.io.CharStreams;
14
15import java.awt.Desktop;
16import java.io.*;
17import java.net.URI;
18import java.net.URISyntaxException;
19import java.util.Arrays;
20import java.util.jar.JarFile;
21
22import javassist.CannotCompileException;
23import javassist.CtClass;
24import javassist.bytecode.Descriptor;
25
26public 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}