@Test public void testDecompress () { byte[] data = new byte[4096]; Random random = new Random(); random.nextBytes(data); byte[] compressedData = GZipUtils.compress(data); assertNotNull(compressedData); byte[] uncompressedData = GZipUtils.decompress(compressedData); assertNotNull(uncompressedData); assertEquals(data.length, uncompressedData.length); for (int i = 0; i < data.length; i++) { assertEquals(data[i], uncompressedData[i]); } }
public static byte[] decompress (byte[] compressedData) { byte[] buffer = new byte[1024]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ByteArrayInputStream bis = new ByteArrayInputStream(compressedData); GZIPInputStream gzipInputStream = new GZIPInputStream(bis)) { int bytes_read; while ((bytes_read = gzipInputStream.read(buffer)) > 0) { baos.write(buffer, 0, bytes_read); } gzipInputStream.close(); baos.close(); } catch (IOException e) { Log.e(LOG_TAG, "unable to decompress resource: ", e); throw new IllegalStateException("unable to decompress resource: ", e); } return baos.toByteArray(); }
GZipUtils { public static byte[] decompress (byte[] compressedData) { byte[] buffer = new byte[1024]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ByteArrayInputStream bis = new ByteArrayInputStream(compressedData); GZIPInputStream gzipInputStream = new GZIPInputStream(bis)) { int bytes_read; while ((bytes_read = gzipInputStream.read(buffer)) > 0) { baos.write(buffer, 0, bytes_read); } gzipInputStream.close(); baos.close(); } catch (IOException e) { Log.e(LOG_TAG, "unable to decompress resource: ", e); throw new IllegalStateException("unable to decompress resource: ", e); } return baos.toByteArray(); } }
GZipUtils { public static byte[] decompress (byte[] compressedData) { byte[] buffer = new byte[1024]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ByteArrayInputStream bis = new ByteArrayInputStream(compressedData); GZIPInputStream gzipInputStream = new GZIPInputStream(bis)) { int bytes_read; while ((bytes_read = gzipInputStream.read(buffer)) > 0) { baos.write(buffer, 0, bytes_read); } gzipInputStream.close(); baos.close(); } catch (IOException e) { Log.e(LOG_TAG, "unable to decompress resource: ", e); throw new IllegalStateException("unable to decompress resource: ", e); } return baos.toByteArray(); } protected  GZipUtils(); }
GZipUtils { public static byte[] decompress (byte[] compressedData) { byte[] buffer = new byte[1024]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ByteArrayInputStream bis = new ByteArrayInputStream(compressedData); GZIPInputStream gzipInputStream = new GZIPInputStream(bis)) { int bytes_read; while ((bytes_read = gzipInputStream.read(buffer)) > 0) { baos.write(buffer, 0, bytes_read); } gzipInputStream.close(); baos.close(); } catch (IOException e) { Log.e(LOG_TAG, "unable to decompress resource: ", e); throw new IllegalStateException("unable to decompress resource: ", e); } return baos.toByteArray(); } protected  GZipUtils(); static byte[] compress(byte[] uncompressedData); static byte[] decompress(byte[] compressedData); }
GZipUtils { public static byte[] decompress (byte[] compressedData) { byte[] buffer = new byte[1024]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ByteArrayInputStream bis = new ByteArrayInputStream(compressedData); GZIPInputStream gzipInputStream = new GZIPInputStream(bis)) { int bytes_read; while ((bytes_read = gzipInputStream.read(buffer)) > 0) { baos.write(buffer, 0, bytes_read); } gzipInputStream.close(); baos.close(); } catch (IOException e) { Log.e(LOG_TAG, "unable to decompress resource: ", e); throw new IllegalStateException("unable to decompress resource: ", e); } return baos.toByteArray(); } protected  GZipUtils(); static byte[] compress(byte[] uncompressedData); static byte[] decompress(byte[] compressedData);  }