1
|
import java.io.File;
|
2
|
import java.io.IOException;
|
3
|
import java.util.List;
|
4
|
|
5
|
import org.codehaus.jackson.map.ObjectMapper;
|
6
|
import org.codehaus.jackson.map.ObjectWriter;
|
7
|
|
8
|
import jdeserialize.content;
|
9
|
import jdeserialize.jdeserialize;
|
10
|
|
11
|
public class Converter extends Thread {
|
12
|
|
13
|
private Deserializer main;
|
14
|
|
15
|
private File input;
|
16
|
private File output;
|
17
|
|
18
|
public Converter(Deserializer main, File inputFilename, File outputFilename) {
|
19
|
this.main = main;
|
20
|
this.input = inputFilename;
|
21
|
this.output = outputFilename;
|
22
|
}
|
23
|
|
24
|
@Override
|
25
|
public void run() {
|
26
|
super.run();
|
27
|
|
28
|
try {
|
29
|
String json = convert(FileWorker.loadByteArray(input));
|
30
|
|
31
|
String title = "Ulo�en� JSON";
|
32
|
if (FileWorker.saveJson(output, json)) {
|
33
|
System.out.println("The JSON file was saved correctly.");
|
34
|
Report.info(title, null, "Ulo�en� JSON souboru prob�hlo v po��dku.");
|
35
|
} else {
|
36
|
System.out.println("There was an error saving the JSON file.");
|
37
|
Report.error(title, null, "P�i ukl�d�n� JSON souboru nastala chyba.");
|
38
|
}
|
39
|
} catch (IOException e) {
|
40
|
System.out.println("There was an error loading the file.");
|
41
|
e.printStackTrace();
|
42
|
Report.error("Na��t�n� souboru", null, "P�i na��t�n� souboru do�lo k chyb�.");
|
43
|
}
|
44
|
|
45
|
main.convertIsComplete();
|
46
|
}
|
47
|
|
48
|
private String convert(byte[] buffer) {
|
49
|
String json = "";
|
50
|
try {
|
51
|
System.out.println("Deserialization begins.");
|
52
|
jdeserialize deserializer = new jdeserialize(buffer);
|
53
|
|
54
|
// gets the "contents" into an array - returnes the deserialization of all
|
55
|
// 'writes' into serialized object via objectOutputStream
|
56
|
List<content> cntnts = deserializer.getContent();
|
57
|
|
58
|
// testing with only first of the contents
|
59
|
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
|
60
|
|
61
|
for(content cnt : cntnts)
|
62
|
{
|
63
|
if(cnt != null)
|
64
|
{
|
65
|
json += cnt.toString();
|
66
|
}
|
67
|
}
|
68
|
|
69
|
System.out.println("Task completed.");
|
70
|
|
71
|
//just for tests
|
72
|
//System.out.println(json);
|
73
|
|
74
|
return json;
|
75
|
} catch (IOException e) {
|
76
|
System.out.println("An error occurred while processing!");
|
77
|
e.printStackTrace();
|
78
|
return null;
|
79
|
}
|
80
|
}
|
81
|
|
82
|
}
|