1 | |
package ca.uhn.hl7v2.hoh.util; |
2 | |
|
3 | |
import java.io.ByteArrayInputStream; |
4 | |
import java.io.ByteArrayOutputStream; |
5 | |
import java.io.IOException; |
6 | |
import java.util.zip.GZIPInputStream; |
7 | |
import java.util.zip.GZIPOutputStream; |
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
public class GZipUtils { |
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | 0 | private GZipUtils() { |
18 | |
|
19 | 0 | } |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
public static byte[] compress(byte[] theBytes) throws IOException { |
25 | 10 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
26 | 10 | GZIPOutputStream gos = new GZIPOutputStream(bos); |
27 | 10 | gos.write(theBytes); |
28 | 10 | gos.close(); |
29 | 10 | return bos.toByteArray(); |
30 | |
} |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public static byte[] uncompress(byte[] theBytes) throws IOException { |
36 | 10 | ByteArrayInputStream bis = new ByteArrayInputStream(theBytes); |
37 | 10 | GZIPInputStream gos = new GZIPInputStream(bis); |
38 | 10 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
39 | 10 | IOUtils.copy(gos, bos); |
40 | 10 | return bos.toByteArray(); |
41 | |
} |
42 | |
|
43 | |
} |