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 private GZipUtils() {
18
19 }
20
21
22
23
24 public static byte[] compress(byte[] theBytes) throws IOException {
25 ByteArrayOutputStream bos = new ByteArrayOutputStream();
26 GZIPOutputStream gos = new GZIPOutputStream(bos);
27 gos.write(theBytes);
28 gos.close();
29 return bos.toByteArray();
30 }
31
32
33
34
35 public static byte[] uncompress(byte[] theBytes) throws IOException {
36 ByteArrayInputStream bis = new ByteArrayInputStream(theBytes);
37 GZIPInputStream gos = new GZIPInputStream(bis);
38 ByteArrayOutputStream bos = new ByteArrayOutputStream();
39 IOUtils.copy(gos, bos);
40 return bos.toByteArray();
41 }
42
43 }