Repository navigation
Expand file tree
/
Copy pathCleaner.java
More file actions
118 lines (102 loc) · 3.19 KB
/
Copy pathCleaner.java
File metadata and controls
118 lines (102 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.io.*;
import java.util.*;
import java.security.*;
import com.rackspacecloud.client.cloudfiles.*;
public class Cleaner {
public static final long sizeBound = (1<<20);
public static final int smallM = 4;
public static final long smallMax = 1024;
public static final long smallMask = 0xF;
public static final int largeM = 1024;
public static final long largeMax = (1<<20);
public static final long largeMask = 0xFFF;
public static final long d = 257;
public static final long q = 0xFFFFFFFFL; // mod q (1<<32)
public static final long Q = 0x100000000L; // mod q (1<<32)
public static long[] modQ = new long[256];
public static long totalChunk = 0;
public static long uniqueChunk = 0;
public static long duplicatedChunk = 0;
public static long byteWith = 0;
public static long byteWithout = 0;
public static FilesClient downloader;
public static void init(long d, int m, long q) {
long dm = 1;
while (m > 0) {
if ((m & 1) == 1)
dm = (dm * d) & q;
m = m / 2;
d = (d * d) & q;
}
for (int i = 0; i < 256; i++)
modQ[i] = (i * dm) & q;
}
public static String bytesToHex(byte[] b) {
char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuffer buf = new StringBuffer();
for (int j=0; j < b.length; j++) {
buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
buf.append(hexDigit[b[j] & 0x0f]);
}
return buf.toString();
}
public static Integer one = new Integer(1);
public static void fileDown(String filepath) {
try {
byte[] FileMeta = downloader.getObject("meta", filepath);
String MetaString = new String(FileMeta);
System.out.println(MetaString);
Scanner sc = new Scanner(MetaString);
String nextSHA1;
Integer val;
while (sc.hasNext()) {
nextSHA1 = sc.next();
byte[] content = downloader.getObject("chunks", nextSHA1);
String StrContent = new String(content);
System.out.println(StrContent);
}
sc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static HashMap<String, Integer> chunkIndex = null;
public static HashMap<String, Integer> chunkSizeIndex = null;
public static void main(String[] args) {
boolean exit = false;
String input, cmd, filepath;
Scanner scan = new Scanner(System.in);
chunkIndex = new HashMap<String, Integer>();
chunkSizeIndex = new HashMap<String, Integer>();
downloader = new FilesClient("group10:group10", "lOnGjObpowS72", "http://10.10.10.1:8080/auth/v1.0");
downloader.setConnectionTimeOut(10000);
try {
downloader.login();
/*BEGIN CLEAN ALL !!!!! */
try {
List<FilesObject> fos = downloader.listObjects("chunks");
for (FilesObject fo:fos){
downloader.deleteObject("chunks", fo.getName());
}
} catch (Exception e) {
e.printStackTrace();
}
downloader.deleteContainer("chunks");
try {
List<FilesObject> fos = downloader.listObjects("meta");
for (FilesObject fo:fos){
downloader.deleteObject("meta", fo.getName());
}
} catch (Exception e) {
e.printStackTrace();
}
downloader.deleteContainer("meta");
/*END CLEAN ALL !!!!! */
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Wish you luck!");
scan.close();
}
}