/** * Uses the {@link CompressorStreamFactory} and the name of the given compressor to create a new * {@link CompressorOutputStream} for the given destination {@link File}. * * @param compressor the invoking compressor * @param destination the file to create the {@link CompressorOutputStream} for * @return a new {@link CompressorOutputStream} * @throws IOException if an I/O error occurs * @throws CompressorException if the compressor name is not known */ static CompressorOutputStream createCompressorOutputStream(CommonsCompressor compressor, File destination) throws IOException, CompressorException { return createCompressorOutputStream(compressor.getCompressionType(), destination); }
static CompressorOutputStream createCompressorOutputStream(CompressionType compressionType, File destination) throws IOException, CompressorException { return createCompressorOutputStream(compressionType.getName(), new FileOutputStream(destination)); }
static CompressorOutputStream createCompressorOutputStream(CompressionType compressionType, File destination) throws IOException, CompressorException { return createCompressorOutputStream(compressionType.getName(), new FileOutputStream(destination)); }
/** * Uses the {@link CompressorStreamFactory} and the name of the given compressor to create a new * {@link CompressorOutputStream} for the given destination {@link File}. * * @param compressor the invoking compressor * @param destination the file to create the {@link CompressorOutputStream} for * @return a new {@link CompressorOutputStream} * @throws IOException if an I/O error occurs * @throws CompressorException if the compressor name is not known */ static CompressorOutputStream createCompressorOutputStream(CommonsCompressor compressor, File destination) throws IOException, CompressorException { return createCompressorOutputStream(compressor.getCompressionType(), destination); }
@Override public void compress(File source, File destination) throws IllegalArgumentException, IOException { assertSource(source); assertDestination(destination); if (destination.isDirectory()) { destination = new File(destination, getCompressedFilename(source)); } CompressorOutputStream compressed = null; BufferedInputStream input = null; try { input = new BufferedInputStream(new FileInputStream(source)); compressed = createCompressorOutputStream(this, destination); IOUtils.copy(input, compressed); } catch (CompressorException e) { throw new IOException(e); } finally { IOUtils.closeQuietly(compressed); IOUtils.closeQuietly(input); } }
@Override public void compress(File source, File destination) throws IllegalArgumentException, IOException { assertSource(source); assertDestination(destination); if (destination.isDirectory()) { destination = new File(destination, getCompressedFilename(source)); } CompressorOutputStream compressed = null; BufferedInputStream input = null; try { input = new BufferedInputStream(new FileInputStream(source)); compressed = createCompressorOutputStream(this, destination); IOUtils.copy(input, compressed); } catch (CompressorException e) { throw new IOException(e); } finally { IOUtils.closeQuietly(compressed); IOUtils.closeQuietly(input); } }