List of usage examples for org.apache.commons.compress.compressors.deflate DeflateCompressorInputStream DeflateCompressorInputStream
public DeflateCompressorInputStream(final InputStream inputStream, final DeflateParameters parameters)
From source file:com.izforge.izpack.installer.unpacker.CompressedFileUnpacker.java
/** * Unpacks a pack file./*from w w w . j a v a2 s . c o m*/ * * @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); } }