-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunner.java
70 lines (52 loc) · 2.1 KB
/
Runner.java
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
66
67
68
69
70
import java.io.*;
import java.util.*;
import java.text.*;
public class Runner {
public static void main(String[] args) {
int i;
String input,output;
long executionTime;
double wordinessParameter;
Wordiness wordiness = new Wordiness();
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
Date date = new Date();;
String suffix = dateFormat.format(date).toString()+".csv";
Huffman huffman = new Huffman();
LZW lzw = new LZW();
File dir = new File(args[0]);
File[] files = dir.listFiles();
for(i=0;i<files.length;i++) {
System.out.println(files[i].getAbsolutePath());
input = FileReader.readFile(files[i].getAbsolutePath());
wordinessParameter = wordiness.calculateWordinessParameter(input);
executionTime = System.currentTimeMillis();
output = huffman.compress(input);
executionTime = System.currentTimeMillis() - executionTime;
compressionPercentage(input,output,"huffman-" + suffix,executionTime,wordinessParameter);
executionTime = System.currentTimeMillis();
output = lzw.compress(input);
executionTime = System.currentTimeMillis() - executionTime;
compressionPercentage(input,output,"lzw-" + suffix,executionTime,wordinessParameter);
}
}
private static void compressionPercentage(String input, String output,String fileName,long executionTime,double wordinessParameter) {
long inputLength = input.length();
long inputSymbolSize = (long) Math.ceil( Math.log(256) / Math.log(2));
long inputSize = inputSymbolSize*inputLength;
try {
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true)));
out.print(inputSize + "," );
out.print(output.length()+",");
out.print(executionTime+",");
out.print(wordinessParameter+",");
out.println(((inputSize - output.length())*1.0 / inputSize) *100 );
System.out.print(inputSize + "," );
System.out.print(output.length()+",");
System.out.print(executionTime+",");
System.out.print(wordinessParameter+",");
System.out.println(((inputSize - output.length())*1.0 / inputSize) *100 );
out.close();
} catch (IOException e) {
}
}
}