blob: eb00446dd0e2a635c8f440b6f08cdd8ec8e0a02a (
plain) (
blame)
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
|
package com.yahoo.container.handler;
import org.json.JSONException;
import org.json.JSONObject;
import javax.xml.bind.DatatypeConverter;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
public class LogReader {
protected static JSONObject readLogs(String logDirectory) throws IOException, JSONException {
JSONObject json = new JSONObject();
File root = new File(logDirectory);
traverse_folder(root, json);
return json;
}
private static void traverse_folder(File root, JSONObject json) throws IOException, JSONException {
for(File child : root.listFiles()) {
JSONObject childJson = new JSONObject();
if(child.isFile()) {
json.put(child.getName(), DatatypeConverter.printBase64Binary(Files.readAllBytes(child.toPath())));
}
else {
json.put(child.getName(), childJson);
traverse_folder(child, childJson);
}
}
}
}
|