|
@ -18,14 +18,18 @@ public class Gzip { |
|
|
return compressed; |
|
|
return compressed; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static byte[] decompress(byte[] compressed) throws IOException { |
|
|
|
|
|
ByteArrayInputStream bis = new ByteArrayInputStream(compressed); |
|
|
|
|
|
GZIPInputStream gis = new GZIPInputStream(bis); |
|
|
|
|
|
return readAll(gis); |
|
|
|
|
|
|
|
|
public static byte[] decompress(byte[] compressed) { |
|
|
|
|
|
try { |
|
|
|
|
|
ByteArrayInputStream bis = new ByteArrayInputStream(compressed); |
|
|
|
|
|
GZIPInputStream gis = new GZIPInputStream(bis); |
|
|
|
|
|
return readAll(gis); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return compressed; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static byte[] readAll(InputStream input) throws IOException { |
|
|
private static byte[] readAll(InputStream input) throws IOException { |
|
|
try( ByteArrayOutputStream output = new ByteArrayOutputStream()){ |
|
|
|
|
|
|
|
|
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { |
|
|
byte[] buffer = new byte[4096]; |
|
|
byte[] buffer = new byte[4096]; |
|
|
int n; |
|
|
int n; |
|
|
while (-1 != (n = input.read(buffer))) { |
|
|
while (-1 != (n = input.read(buffer))) { |
|
|