-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathZipHelper.java
More file actions
54 lines (48 loc) · 1.67 KB
/
Copy pathZipHelper.java
File metadata and controls
54 lines (48 loc) · 1.67 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
package jaskell.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
public class ZipHelper {
static public byte[] decompressByteArray(byte[] bytes, int buffer_size) throws DataFormatException, IOException {
ByteArrayOutputStream baos = null;
Inflater iflr = new Inflater();
iflr.setInput(bytes);
baos = new ByteArrayOutputStream();
byte[] tmp = new byte[buffer_size];
try{
while(!iflr.finished()){
int size = iflr.inflate(tmp);
baos.write(tmp, 0, size);
}
} finally {
baos.close();
}
return baos.toByteArray();
}
static public byte[] decompressByteArray(byte[] bytes) throws DataFormatException, IOException {
return decompressByteArray(bytes, 64);
}
static public byte[] compressByteArray(byte[] bytes, int buffer_size) throws DataFormatException, IOException {
ByteArrayOutputStream baos = null;
Deflater dflr = new Deflater();
dflr.setInput(bytes);
dflr.finish();
baos = new ByteArrayOutputStream();
byte[] tmp = new byte[buffer_size];
try{
while(!dflr.finished()){
int size = dflr.deflate(tmp);
baos.write(tmp, 0, size);
}
} finally {
dflr.end();
baos.close();
}
return baos.toByteArray();
}
static public byte[] compressByteArray(byte[] bytes) throws DataFormatException, IOException {
return compressByteArray(bytes, 64);
}
}