root / src / utils / Utils.java
History | View | Annotate | Download (1.47 KB)
1 | 1 | up20140508 | package utils; |
---|---|---|---|
2 | |||
3 | import channels.McChannel; |
||
4 | import channels.MdbChannel; |
||
5 | import channels.MdrChannel; |
||
6 | |||
7 | import java.net.*; |
||
8 | import java.util.ArrayList; |
||
9 | import java.util.HashMap; |
||
10 | |||
11 | |||
12 | public class Utils { |
||
13 | public static int BUFFER_SIZE = 256; |
||
14 | public static MulticastSocket mcSocket; |
||
15 | public static MulticastSocket mdbSocket; |
||
16 | public static MulticastSocket mdrSocket; |
||
17 | |||
18 | public static String version = "1.0"; |
||
19 | public static String crlf = "\\r\\n"; |
||
20 | |||
21 | public static McChannel mcChannel; |
||
22 | public static MdbChannel mdbChannel; |
||
23 | public static MdrChannel mdrChannel; |
||
24 | |||
25 | public static boolean chunkReceived = false; |
||
26 | public static int restorePeer = 0; |
||
27 | public static boolean receivedAllChunks = false; |
||
28 | |||
29 | public static HashMap<String,String> hashDatabase = new HashMap<String, String>(); |
||
30 | public static HashMap<String, ArrayList<Integer>> storedChunks = new HashMap<>(); |
||
31 | |||
32 | |||
33 | public static String encodeHexString(byte[] byteArray) { //https://www.baeldung.com/java-byte-arrays-hex-strings |
||
34 | StringBuffer hexStringBuffer = new StringBuffer(); |
||
35 | for (int i = 0; i < byteArray.length; i++) { |
||
36 | hexStringBuffer.append(byteToHex(byteArray[i])); |
||
37 | } |
||
38 | return hexStringBuffer.toString();
|
||
39 | } |
||
40 | |||
41 | public static String byteToHex(byte num) { |
||
42 | char[] hexDigits = new char[2]; |
||
43 | hexDigits[0] = Character.forDigit((num >> 4) & 0xF, 16); |
||
44 | hexDigits[1] = Character.forDigit((num & 0xF), 16); |
||
45 | return new String(hexDigits); |
||
46 | } |
||
47 | } |