@Test public void testCompress() throws CompressionException { String data = "Hello World!"; DeflateCompressor compressor = new DeflateCompressor(); byte[] compressed = compressor.compress(data, null); Assert.assertNotEquals(data, compressed, "DeflateCompressor : given data did not compress."); }
public byte[] compress(final String data, byte[] uploadFile) throws CompressionException { if (!StringUtils.hasText(data)) { return null; } ByteArrayOutputStream baos = null; OutputStream deflater = null; byte[] compressedData = null; try { baos = new ByteArrayOutputStream(); deflater = new DeflaterOutputStream(baos); deflater.write(data.getBytes()); if (uploadFile != null) { deflater.write(uploadFile); } deflater.close(); compressedData = baos.toByteArray(); return compressedData; } catch (IOException ioe) { throw new CompressionException("IOException while compress the data using Deflate compression.", ioe); } finally { if (baos != null) { try { baos.close(); } catch (IOException e) { LOG.error("Unable to close ByteArrayOutputStream."); } } } }
DeflateCompressor implements ICompressor { public byte[] compress(final String data, byte[] uploadFile) throws CompressionException { if (!StringUtils.hasText(data)) { return null; } ByteArrayOutputStream baos = null; OutputStream deflater = null; byte[] compressedData = null; try { baos = new ByteArrayOutputStream(); deflater = new DeflaterOutputStream(baos); deflater.write(data.getBytes()); if (uploadFile != null) { deflater.write(uploadFile); } deflater.close(); compressedData = baos.toByteArray(); return compressedData; } catch (IOException ioe) { throw new CompressionException("IOException while compress the data using Deflate compression.", ioe); } finally { if (baos != null) { try { baos.close(); } catch (IOException e) { LOG.error("Unable to close ByteArrayOutputStream."); } } } } }
DeflateCompressor implements ICompressor { public byte[] compress(final String data, byte[] uploadFile) throws CompressionException { if (!StringUtils.hasText(data)) { return null; } ByteArrayOutputStream baos = null; OutputStream deflater = null; byte[] compressedData = null; try { baos = new ByteArrayOutputStream(); deflater = new DeflaterOutputStream(baos); deflater.write(data.getBytes()); if (uploadFile != null) { deflater.write(uploadFile); } deflater.close(); compressedData = baos.toByteArray(); return compressedData; } catch (IOException ioe) { throw new CompressionException("IOException while compress the data using Deflate compression.", ioe); } finally { if (baos != null) { try { baos.close(); } catch (IOException e) { LOG.error("Unable to close ByteArrayOutputStream."); } } } }  }
DeflateCompressor implements ICompressor { public byte[] compress(final String data, byte[] uploadFile) throws CompressionException { if (!StringUtils.hasText(data)) { return null; } ByteArrayOutputStream baos = null; OutputStream deflater = null; byte[] compressedData = null; try { baos = new ByteArrayOutputStream(); deflater = new DeflaterOutputStream(baos); deflater.write(data.getBytes()); if (uploadFile != null) { deflater.write(uploadFile); } deflater.close(); compressedData = baos.toByteArray(); return compressedData; } catch (IOException ioe) { throw new CompressionException("IOException while compress the data using Deflate compression.", 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); }
DeflateCompressor implements ICompressor { public byte[] compress(final String data, byte[] uploadFile) throws CompressionException { if (!StringUtils.hasText(data)) { return null; } ByteArrayOutputStream baos = null; OutputStream deflater = null; byte[] compressedData = null; try { baos = new ByteArrayOutputStream(); deflater = new DeflaterOutputStream(baos); deflater.write(data.getBytes()); if (uploadFile != null) { deflater.write(uploadFile); } deflater.close(); compressedData = baos.toByteArray(); return compressedData; } catch (IOException ioe) { throw new CompressionException("IOException while compress the data using Deflate compression.", 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);  }