-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCompressTest.java
More file actions
45 lines (35 loc) · 1.53 KB
/
CompressTest.java
File metadata and controls
45 lines (35 loc) · 1.53 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
package compress;
import java.io.IOException;
import java.util.Random;
import priv.dengjl.compress.util.CompressUtil;
public class CompressTest {
public static final String allChar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static String generateString(int length) {
StringBuffer sb = new StringBuffer();
Random random = new Random();
for (int i = 0; i < length; i++) {
sb.append(allChar.charAt(random.nextInt(allChar.length())));
}
return sb.toString();
}
public static void main(String[] args) throws IOException {
String data = generateString(1024 * 10);
// System.out.println("压缩前数据内容:" + data);
byte[] dataBytes = data.getBytes();
System.out.println("压缩前数据大小:" + dataBytes.length);
CompressUtil[] values = CompressUtil.values();
for (CompressUtil compressUtil : values) {
System.out.println("===================: " + compressUtil.name());
long start = System.currentTimeMillis();
byte[] resultBytes = compressUtil.compress(dataBytes);
System.out.println("压缩后数据大小:" + resultBytes.length);
byte[] uncompressBytes = compressUtil.uncompress(resultBytes);
System.out.println("解压后数据大小:" + uncompressBytes.length);
String result = new String(uncompressBytes);
// System.out.println("解压后数据内容:" + result);
System.out.println("压缩时间(ms):" + (System.currentTimeMillis() - start));
System.out.println("===================: " + compressUtil.name());
System.out.println();
}
}
}