diff options
Diffstat (limited to 'client/trunk/src/com/fourisland')
4 files changed, 96 insertions, 1 deletions
diff --git a/client/trunk/src/com/fourisland/instadisc/CloseObjectThread.java b/client/trunk/src/com/fourisland/instadisc/CloseObjectThread.java new file mode 100644 index 0000000..af8cecc --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/CloseObjectThread.java | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.instadisc; | ||
7 | |||
8 | import java.io.IOException; | ||
9 | import java.net.ServerSocket; | ||
10 | import java.util.logging.Level; | ||
11 | import java.util.logging.Logger; | ||
12 | |||
13 | /** | ||
14 | * | ||
15 | * @author hatkirby | ||
16 | */ | ||
17 | class CloseObjectThread implements Runnable{ | ||
18 | |||
19 | ServerSocket svr; | ||
20 | |||
21 | public CloseObjectThread(ServerSocket svr) { | ||
22 | this.svr = svr; | ||
23 | } | ||
24 | |||
25 | public void run() { | ||
26 | try { | ||
27 | svr.close(); | ||
28 | } catch (IOException ex) { | ||
29 | Logger.getLogger(CloseObjectThread.class.getName()).log(Level.SEVERE, null, ex); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | } | ||
diff --git a/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java b/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java index 69a8e49..fcde8d8 100644 --- a/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java +++ b/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java | |||
@@ -30,6 +30,7 @@ public class InstaDiscThread implements Runnable { | |||
30 | ServerSocket svr = new ServerSocket(); | 30 | ServerSocket svr = new ServerSocket(); |
31 | java.net.InetSocketAddress addr = new java.net.InetSocketAddress(4444); | 31 | java.net.InetSocketAddress addr = new java.net.InetSocketAddress(4444); |
32 | svr.bind(addr); | 32 | svr.bind(addr); |
33 | Runtime.getRuntime().addShutdownHook(new Thread(new CloseObjectThread(svr))); | ||
33 | while (!cancelled) { | 34 | while (!cancelled) { |
34 | try { | 35 | try { |
35 | Socket s = svr.accept(); | 36 | Socket s = svr.accept(); |
@@ -90,7 +91,7 @@ class HandleItemThread implements Runnable { | |||
90 | try { | 91 | try { |
91 | String[] nameVal = headers[i].split(": "); | 92 | String[] nameVal = headers[i].split(": "); |
92 | String name = nameVal[0]; | 93 | String name = nameVal[0]; |
93 | String value = nameVal[1]; | 94 | String value = nameVal[1].trim(); |
94 | headerMap.put(name, value); | 95 | headerMap.put(name, value); |
95 | } catch (Exception ex) { | 96 | } catch (Exception ex) { |
96 | break; | 97 | break; |
diff --git a/client/trunk/src/com/fourisland/instadisc/Item/Item.java b/client/trunk/src/com/fourisland/instadisc/Item/Item.java index f13ec3d..fd52d5f 100644 --- a/client/trunk/src/com/fourisland/instadisc/Item/Item.java +++ b/client/trunk/src/com/fourisland/instadisc/Item/Item.java | |||
@@ -23,5 +23,9 @@ public class Item { | |||
23 | public void start() | 23 | public void start() |
24 | { | 24 | { |
25 | WellFormedItem wfi = new WellFormedItem(this); | 25 | WellFormedItem wfi = new WellFormedItem(this); |
26 | if (wfi.check()) | ||
27 | { | ||
28 | |||
29 | } | ||
26 | } | 30 | } |
27 | } | 31 | } |
diff --git a/client/trunk/src/com/fourisland/instadisc/Item/MD5.java b/client/trunk/src/com/fourisland/instadisc/Item/MD5.java new file mode 100644 index 0000000..9c4d5aa --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/Item/MD5.java | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | package com.fourisland.instadisc.Item; | ||
6 | |||
7 | import java.security.MessageDigest; | ||
8 | import java.util.logging.Level; | ||
9 | import java.util.logging.Logger; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public class MD5 { | ||
16 | |||
17 | String ver; | ||
18 | |||
19 | public MD5(String ver) { | ||
20 | this.ver = ver; | ||
21 | } | ||
22 | |||
23 | public String hash() | ||
24 | { | ||
25 | StringBuilder verify = new StringBuilder(); | ||
26 | try { | ||
27 | MessageDigest md5 = MessageDigest.getInstance("MD5"); | ||
28 | int i = 0; | ||
29 | byte[] create = new byte[ver.length()]; | ||
30 | for (i = 0; i < ver.length(); i++) { | ||
31 | create[i] = (byte) ver.charAt(i); | ||
32 | } | ||
33 | byte buffer[] = md5.digest(create); | ||
34 | for (i = 0; i < buffer.length; i++) { | ||
35 | String hex = Integer.toHexString(buffer[i]); | ||
36 | verify.append(pad(hex.substring(max(hex.length() - 2, 0)),"0",2)); | ||
37 | } | ||
38 | } catch (Exception ex) { | ||
39 | Logger.getLogger(WellFormedItem.class.getName()).log(Level.SEVERE, null, ex); | ||
40 | } | ||
41 | return verify.toString(); | ||
42 | } | ||
43 | |||
44 | private int max(int x, int y) | ||
45 | { | ||
46 | return (x > y ? x : y); | ||
47 | } | ||
48 | |||
49 | private String pad(String in, String pad, int len) | ||
50 | { | ||
51 | while (in.length() < len) | ||
52 | { | ||
53 | in = pad + in; | ||
54 | } | ||
55 | return in; | ||
56 | } | ||
57 | } | ||