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