-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.java
More file actions
65 lines (56 loc) · 2.03 KB
/
Copy pathmain.java
File metadata and controls
65 lines (56 loc) · 2.03 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
57
58
59
60
61
62
63
64
65
import java.awt.EventQueue;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.awt.Desktop;
import java.net.URI;
public class main {
public static void main(String[] args) throws Exception {
long startTime = System.nanoTime();
long beforeUsedMem=Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory();
String orgFile = "./inputStringFile.txt";
String dotFile = "./outputDescriptionFile.dot";
String givenString = readFile(orgFile);
HuffManDisplay h = new HuffManDisplay(givenString, dotFile);
h.DisplayHuffman();
h.WriteToDictionary();
long endTime = System.nanoTime();
System.out.println("Time Taken " + (endTime - startTime) + " ns");
long afterUsedMem=Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory();
long actualMemUsed=afterUsedMem-beforeUsedMem;
int dataSize = 1024 * 1024;
System.out.println("Memory Used " + (actualMemUsed)/dataSize + "MB");
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
HuffmanGUI frame = new HuffmanGUI(h.DataArray, h.encodedString, h.DecodedString, h.sizeAfterCoding,
h.sizeForGivenString, h.reductionPercentage);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
Desktop d = Desktop.getDesktop();
Runtime.getRuntime().exec("dot -Tpng ./outputDescriptionFile.dot -o ./finalOutputHuffmanTree.png");
String filePath = "./finalOutputHuffmanTree.png";
File file = new File(filePath);
URI uri = file.toURI();
d.browse(new URI(uri.toString()));
}
public static String readFile(String fname) {
StringBuilder sb = new StringBuilder();
File filename = new File(fname);
try (BufferedReader in = new BufferedReader(new FileReader(filename))) {
String line = in.readLine();
while (line != null) {
sb.append(line + "");
line = in.readLine();
}
} catch (IOException e) {
System.out.println(e);
}
return sb.toString();
}
}