-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
47 lines (34 loc) · 1016 Bytes
/
test.java
File metadata and controls
47 lines (34 loc) · 1016 Bytes
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
import java.util.Arrays;
import MakeHuffmanTree.MakeHuffmanTree;
import Encode.Encode;
import java.util.BitSet;
import java.io.FileOutputStream;
import java.io.IOException;
class test {
public static void main(String args[])
{
String text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
String [] codes = new String [128];
for (int i=0;i<128;i++)
codes[i]="";
MakeHuffmanTree tree = new MakeHuffmanTree(text);
tree.MakeTree(codes);
Encode en = new Encode(text);
String res ="";
res = en.encode(codes);
BitSet bits = new BitSet(res.length());
for(int i=0;i<res.length() ;i++)
bits.set(i);
byte[] bytes = new byte[bits.length()/8+1];
for (int i=0; i<bits.length(); i++) {
if (bits.get(i)) {
bytes[bytes.length-i/8-1] |= 1<<(i%8);
}
}
try (FileOutputStream fileOuputStream = new FileOutputStream("./abc.txt")) {
fileOuputStream.write(bytes);
} catch (IOException e) {
e.printStackTrace();
}
}
}