- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
Latest commit
56 lines (40 loc) · 1.83 KB
/
Copy pathTest.java
File metadata and controls
56 lines (40 loc) · 1.83 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
importjava.util.*;
importjava.util.stream.*;
importjava.net.URI;
importjava.nio.file.Path;
importjava.nio.file.*;
importstaticjava.lang.System.out;
publicclassTest {
publicstaticvoidmain(String[] args) throwsThrowable {
Map<String, String> env = newHashMap<>();
env.put("create", "true");
Stringzip_path = args[0];
Stringrand_files_dir_name = args[1];
Stream<Path> file_stream = Files.list(Paths.get(rand_files_dir_name));
intfile_count = file_stream.collect(Collectors.toList()).size();
ArrayList<Integer> runtimes = newArrayList<Integer>();
URIuri = URI.create("jar:file:" + zip_path);
booleandeleted = Files.deleteIfExists(Paths.get(zip_path));
out.println(deleted);
try (FileSystemzipfs = FileSystems.newFileSystem(uri, env)) {
Pathrand_dir = zipfs.getPath(rand_files_dir_name);
Files.createDirectory(rand_dir);
for(inti = 1; i <= file_count; i++) {
longstartTime = System.nanoTime();
Stringrand_file = rand_files_dir_name + "/" + Integer.toString(i) + "_rand.txt";
PathexternalTxtFile = Paths.get(rand_file);
PathpathInZip = zipfs.getPath(rand_file);
Files.copy(externalTxtFile, pathInZip, StandardCopyOption.REPLACE_EXISTING);
longendTime = System.nanoTime();
intruntime = (int)(endTime - startTime)/1000000;
out.println(Integer.toString(i) + " -- " + Integer.toString(runtime) + "ms");
runtimes.add(runtime);
}
}
doubleruntimeSum = 0;
for(inti = 0; i < runtimes.size(); i++) {
runtimeSum += runtimes.get(i);
}
out.print("Avg: " + Double.toString(runtimeSum / runtimes.size()));
}
}