@Test public void testCompress() { String data = "Hello World!"; try { GZIPCompressor compressor = new GZIPCompressor(); byte[] compressed = compressor.compress(data, null); Assert.assertNotEquals(data, compressed, "GZIPCompressor : given data did not compress."); } catch (CompressionException e) { e.printStackTrace(); } }
public byte[] compress(final String data, byte[] uploadFile) throws CompressionException { if (!StringUtils.hasText(data)) { return null; } ByteArrayOutputStream baos = null; OutputStream gzout = null; byte[] compressedData = null; try { baos = new ByteArrayOutputStream(); gzout = new GZIPOutputStream(baos); gzout.write(data.getBytes(StandardCharsets.UTF_8)); if (uploadFile != null) { gzout.write(uploadFile); } gzout.close(); compressedData = baos.toByteArray(); return compressedData; } catch (IOException ioe) { LOG.error("IOException while compress the data using GZIP compression.", ioe); throw new CompressionException(ioe); } finally { if (baos != null) { try { baos.close(); } catch (IOException e) { LOG.error("Unable to close ByteArrayOutputStream."); } } } }
GZIPCompressor implements ICompressor { public byte[] compress(final String data, byte[] uploadFile) throws CompressionException { if (!StringUtils.hasText(data)) { return null; } ByteArrayOutputStream baos = null; OutputStream gzout = null; byte[] compressedData = null; try { baos = new ByteArrayOutputStream(); gzout = new GZIPOutputStream(baos); gzout.write(data.getBytes(StandardCharsets.UTF_8)); if (uploadFile != null) { gzout.write(uploadFile); } gzout.close(); compressedData = baos.toByteArray(); return compressedData; } catch (IOException ioe) { LOG.error("IOException while compress the data using GZIP compression.", ioe); throw new CompressionException(ioe); } finally { if (baos != null) { try { baos.close(); } catch (IOException e) { LOG.error("Unable to close ByteArrayOutputStream."); } } } } }
GZIPCompressor implements ICompressor { public byte[] compress(final String data, byte[] uploadFile) throws CompressionException { if (!StringUtils.hasText(data)) { return null; } ByteArrayOutputStream baos = null; OutputStream gzout = null; byte[] compressedData = null; try { baos = new ByteArrayOutputStream(); gzout = new GZIPOutputStream(baos); gzout.write(data.getBytes(StandardCharsets.UTF_8)); if (uploadFile != null) { gzout.write(uploadFile); } gzout.close(); compressedData = baos.toByteArray(); return compressedData; } catch (IOException ioe) { LOG.error("IOException while compress the data using GZIP compression.", ioe); throw new CompressionException(ioe); } finally { if (baos != null) { try { baos.close(); } catch (IOException e) { LOG.error("Unable to close ByteArrayOutputStream."); } } } }  }
GZIPCompressor implements ICompressor { public byte[] compress(final String data, byte[] uploadFile) throws CompressionException { if (!StringUtils.hasText(data)) { return null; } ByteArrayOutputStream baos = null; OutputStream gzout = null; byte[] compressedData = null; try { baos = new ByteArrayOutputStream(); gzout = new GZIPOutputStream(baos); gzout.write(data.getBytes(StandardCharsets.UTF_8)); if (uploadFile != null) { gzout.write(uploadFile); } gzout.close(); compressedData = baos.toByteArray(); return compressedData; } catch (IOException ioe) { LOG.error("IOException while compress the data using GZIP compression.", ioe); throw new CompressionException(ioe); } finally { if (baos != null) { try { baos.close(); } catch (IOException e) { LOG.error("Unable to close ByteArrayOutputStream."); } } } }  byte[] compress(final String data, byte[] uploadFile); OutputStream decompress(final InputStream in); }
GZIPCompressor implements ICompressor { public byte[] compress(final String data, byte[] uploadFile) throws CompressionException { if (!StringUtils.hasText(data)) { return null; } ByteArrayOutputStream baos = null; OutputStream gzout = null; byte[] compressedData = null; try { baos = new ByteArrayOutputStream(); gzout = new GZIPOutputStream(baos); gzout.write(data.getBytes(StandardCharsets.UTF_8)); if (uploadFile != null) { gzout.write(uploadFile); } gzout.close(); compressedData = baos.toByteArray(); return compressedData; } catch (IOException ioe) { LOG.error("IOException while compress the data using GZIP compression.", ioe); throw new CompressionException(ioe); } finally { if (baos != null) { try { baos.close(); } catch (IOException e) { LOG.error("Unable to close ByteArrayOutputStream."); } } } }  byte[] compress(final String data, byte[] uploadFile); OutputStream decompress(final InputStream in);  }