-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtag.java
More file actions
117 lines (89 loc) · 2.59 KB
/
Copy pathtag.java
File metadata and controls
117 lines (89 loc) · 2.59 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package LZ78;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
public class tag {
public int pointer;
public char cha;
public static ArrayList<Boolean> binaryTag = new ArrayList<Boolean>(32);
public static ArrayList<Integer> binaryNum = new ArrayList<Integer>(32);
public static int numberTages;
public String toString() {
return pointer + " " + cha;
}
public void prepareTag(binNum poi ) {
ArrayList<Boolean> arPoi = poi.toBinary(pointer) , ch = binNum.fromChar(cha);
for (int i = 0; i < arPoi.size(); i++) {
binaryTag.add(arPoi.get(i));
}
for (int i = 0; i < ch.size(); i++) {
binaryTag.add(ch.get(i));
}
}
public static void genrate() {
int num = 0;
for (int i = 0, j = 1; i < binaryTag.size(); i++, j++) {
if (j % 32 == 0) {
j = 1;
binaryNum.add(num);
num = (int) ((binaryTag.get(i) ? 1 : 0) * Math.pow(2, j - 1));
} else
num += (binaryTag.get(i) ? 1 : 0) * Math.pow(2, j - 1);
}
if (num > 0)
binaryNum.add(num);
}
public static void createBinaryNum() {
binaryTag = new ArrayList<Boolean>(32);
int num = 0;
for (int i = 0; i < binaryNum.size(); i++) {
num = binaryNum.get(i);
for (int j2 = 0; j2 < 31; j2++) {
binaryTag.add((num % 2 == 1 ? true : false));
num /= 2;
}
}
}
public static ArrayList<tag> deGenrate(binNum poi ) {
createBinaryNum();
ArrayList<tag> list = new ArrayList<tag>();
int tagSize = 8 + poi.binLen ;
for (int i = 0, j2 = 0; i < binaryTag.size() && j2 < numberTages; i += tagSize, j2++) {
tag temp = new tag();
ArrayList<Boolean> po = new ArrayList<Boolean>();
for (int j = i; j < i + poi.binLen; j++) {
po.add(binaryTag.get(j));
}
temp.pointer = poi.toDecimal(po);
ArrayList<Boolean> ch = new ArrayList<Boolean>();
for (int j = i + poi.binLen ; j < i + poi.binLen + 8 && j < binaryTag.size(); j++) {
ch.add(binaryTag.get(j));
}
temp.cha = binNum.toChar(ch);
list.add(temp);
}
return list;
}
public static void saveTag(DataOutputStream out, binNum poi)
throws IOException {
out.writeShort(poi.binLen);
genrate();
out.writeShort(binaryTag.size() / (poi.binLen + 8));
for (int i = 0; i < binaryNum.size(); i++) {
out.writeInt(binaryNum.get(i));
}
}
public static void readTag(DataInputStream in, binNum poi, binNum le) {
binaryNum = new ArrayList<Integer>(32);
try {
poi.SetMaxBinLen(in.readShort());
numberTages = in.readShort();
for (int i = 0; true; i++) {
binaryNum.add(in.readInt());
}
} catch (Exception e) {
return;
}
}
}