-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFile.java
More file actions
48 lines (35 loc) · 1.58 KB
/
ReadFile.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
import java.util.*;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.*;
import static java.lang.System.out;
import java.util.stream.*;
public class ReadFile {
public static void main(String[] args) throws Throwable {
Map<String, String> env = new HashMap<>();
env.put("create", "true");
String zip_path = args[0];
String rand_files_dir_name = args[1];
URI uri = URI.create("jar:file:" + zip_path);
ArrayList<Integer> runtimes = new ArrayList<Integer>();
try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
Stream<Path> file_stream = Files.list(zipfs.getPath(rand_files_dir_name));
int file_count = file_stream.collect(Collectors.toList()).size();
out.println("Files: " + Integer.toString(file_count));
for(int i = 1; i <= file_count; i++) {
long startTime = System.nanoTime();
Path pathInZip = zipfs.getPath(rand_files_dir_name + "/" + Integer.toString(i) + "_rand.txt");
byte[] allBytes = Files.readAllBytes(pathInZip);
long endTime = System.nanoTime();
int runtime = (int)(endTime - startTime)/1000000;
runtimes.add(runtime);
out.println(Integer.toString(i) + " -- " + Integer.toString(runtime) + "ms");
}
}
double runtimeSum = 0;
for(int i = 0; i < runtimes.size(); i++) {
runtimeSum += runtimes.get(i);
}
out.print("Avg: " + Double.toString(runtimeSum / runtimes.size()));
}
}