File archive = new File("/home/thrau/archive.tar.gz"); File destination = new File("/home/thrau/archive/"); Archiver archiver = ArchiverFactory.createArchiver("tar", "gz"); archiver.extract(archive, destination);
private void unTarGz(File archive) throws IOException { Archiver archiver = createArchiver(TAR, GZIP); archiver.extract(archive, archive.getParentFile()); log.trace("unTarGz {}", archive); }
@Override public void extract(InputStream archive, File destination) throws IOException { IOUtils.requireDirectory(destination); archiver.extract(compressor.decompressingStream(archive), destination); }
@Override public void extract(File archive, File destination) throws IOException { assertExtractSource(archive); IOUtils.requireDirectory(destination); ArchiveInputStream input = null; try { input = createArchiveInputStream(archive); extract(input, destination); } finally { IOUtils.closeQuietly(input); } }
/** * Creates an Archiver for the given archive format that uses compression. * * @param archiveFormat the archive format * @param compression the compression algorithm * @return a new Archiver instance that also handles compression */ public static Archiver createArchiver(ArchiveFormat archiveFormat, CompressionType compression) { CommonsArchiver archiver = new CommonsArchiver(archiveFormat); CommonsCompressor compressor = new CommonsCompressor(compression); return new ArchiverCompressorDecorator(archiver, compressor); }
/** * @see {@link ArchiveStreamFactory#createArchiveInputStream(String, InputStream)} */ static ArchiveInputStream createArchiveInputStream(CommonsArchiver archiver, InputStream in) throws ArchiveException { return createArchiveInputStream(archiver.getArchiveFormat(), in); }
/** * @see {@link ArchiveStreamFactory#createArchiveInputStream(String, InputStream)} */ static ArchiveInputStream createArchiveInputStream(ArchiveFormat archiveFormat, InputStream in) throws ArchiveException { return createArchiveInputStream(archiveFormat.getName(), in); }
private void closeCurrentEntryStream() { InputStream stream = getCurrentEntryStream(); IOUtils.closeQuietly(stream); currentEntryStream = null; }
@Override public File create(String archive, File destination, File source) throws IOException { return create(archive, destination, IOUtils.filesContainedIn(source)); }
@Override public String getFilenameExtension() { return getCompressionType().getDefaultFileExtension(); }
@Override public ArchiveStream stream(File archive) throws IOException { return new CommonsArchiveStream(createArchiveInputStream(archive)); }
@Override public File create(String archive, File destination, File source) throws IOException { return create(archive, destination, IOUtils.filesContainedIn(source)); }
/** * 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); }
private void unBZip2(File archive) throws IOException { Archiver archiver = createArchiver(TAR, BZIP2); archiver.extract(archive, archive.getParentFile()); log.trace("Unbzip2 {}", archive); }
@Override public void extract(File archive, File destination) throws IOException { assertExtractSource(archive); IOUtils.requireDirectory(destination); ArchiveInputStream input = null; try { input = createArchiveInputStream(archive); extract(input, destination); } finally { IOUtils.closeQuietly(input); } }
@Override public void extract(InputStream archive, File destination) throws IOException { IOUtils.requireDirectory(destination); archiver.extract(compressor.decompressingStream(archive), destination); }
/** * Creates an Archiver for the given archive format that uses compression. * * @param archiveFormat the archive format * @param compression the compression algorithm * @return a new Archiver instance that also handles compression */ public static Archiver createArchiver(ArchiveFormat archiveFormat, CompressionType compression) { CommonsArchiver archiver = new CommonsArchiver(archiveFormat); CommonsCompressor compressor = new CommonsCompressor(compression); return new ArchiverCompressorDecorator(archiver, compressor); }
/** * @see {@link ArchiveStreamFactory#createArchiveInputStream(String, InputStream)} */ static ArchiveInputStream createArchiveInputStream(CommonsArchiver archiver, InputStream in) throws ArchiveException { return createArchiveInputStream(archiver.getArchiveFormat(), in); }
/** * @see {@link ArchiveStreamFactory#createArchiveInputStream(String, InputStream)} */ static ArchiveInputStream createArchiveInputStream(ArchiveFormat archiveFormat, InputStream in) throws ArchiveException { return createArchiveInputStream(archiveFormat.getName(), in); }
private void closeCurrentEntryStream() { InputStream stream = getCurrentEntryStream(); IOUtils.closeQuietly(stream); currentEntryStream = null; }