List of usage examples for org.apache.commons.compress.compressors.deflate DeflateParameters DeflateParameters
DeflateParameters
From source file:com.izforge.izpack.installer.unpacker.CompressedFileUnpacker.java
/** * Unpacks a pack file.// w ww . ja v a2s. c om * * @param file the pack file meta-data * @param packInputStream the pack input stream * @param target the target * @throws IOException for any I/O error * @throws InstallerException for any installer exception */ @Override public void unpack(PackFile file, InputStream packInputStream, File target) throws IOException, InstallerException { File tmpfile = File.createTempFile("izpack-uncompress", null, FileUtils.getTempDirectory()); OutputStream fo = null; InputStream finalStream = null; try { fo = IOUtils.buffer(FileUtils.openOutputStream(tmpfile)); IOUtils.copyLarge(packInputStream, fo, 0, file.size()); fo.flush(); fo.close(); InputStream in = IOUtils.buffer(FileUtils.openInputStream(tmpfile)); if (compressionFormat == PackCompression.DEFLATE) { DeflateParameters deflateParameters = new DeflateParameters(); deflateParameters.setCompressionLevel(Deflater.BEST_COMPRESSION); finalStream = new DeflateCompressorInputStream(in, deflateParameters); } else { finalStream = new CompressorStreamFactory().createCompressorInputStream(compressionFormat.toName(), in); } copy(file, finalStream, target); } catch (CompressorException e) { throw new IOException(e); } finally { IOUtils.closeQuietly(fo); IOUtils.closeQuietly(finalStream); FileUtils.deleteQuietly(tmpfile); } }
From source file:com.chenshu.compress.CompressOldTest.java
@Benchmark public int commonsDeflateCompress() { ByteArrayOutputStream bout = null; DeflateCompressorOutputStream dout = null; try {// www . j a va 2 s . c o m DeflateParameters p = new DeflateParameters(); p.setCompressionLevel(level); bout = new ByteArrayOutputStream(data.length); dout = new DeflateCompressorOutputStream(bout, p); dout.write(data); } catch (IOException e) { e.printStackTrace(); } finally { if (dout != null) { try { dout.close(); } catch (IOException e) { e.printStackTrace(); } } if (bout != null) { try { bout.close(); } catch (IOException e) { e.printStackTrace(); } } } byte[] bs = bout.toByteArray(); return bs.length; }