@Override public File create(String archive, File destination, File source) throws IOException { return create(archive, destination, IOUtils.filesContainedIn(source)); }
/** * 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); }
@Override public File create(String archive, File destination, File... sources) throws IOException { IOUtils.requireDirectory(destination); File temp = File.createTempFile(destination.getName(), archiver.getFilenameExtension(), destination); File destinationArchive = null; try { temp = archiver.create(temp.getName(), temp.getParentFile(), sources); destinationArchive = new File(destination, getArchiveFileName(archive)); compressor.compress(temp, destinationArchive); } finally { temp.delete(); } return destinationArchive; }
/** * Returns a file name from the given archive name. The file extension suffix will be appended according to what is * already present. * <br> * E.g. if the compressor uses the file extension "gz", the archiver "tar", and passed argument is "archive.tar", * the returned value will be "archive.tar.gz". * * @param archive the existing archive file name * @return the normalized archive file name including the correct file name extension */ private String getArchiveFileName(String archive) { String fileExtension = getFilenameExtension(); if (archive.endsWith(fileExtension)) { return archive; } else if (archive.endsWith(archiver.getFilenameExtension())) { return archive + compressor.getFilenameExtension(); } else { return archive + fileExtension; } }
/** * 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); }
@Override public File create(String archive, File destination, File... sources) throws IOException { IOUtils.requireDirectory(destination); File temp = File.createTempFile(destination.getName(), archiver.getFilenameExtension(), destination); File destinationArchive = null; try { temp = archiver.create(temp.getName(), temp.getParentFile(), sources); destinationArchive = new File(destination, getArchiveFileName(archive)); compressor.compress(temp, destinationArchive); } finally { temp.delete(); } return destinationArchive; }
/** * Returns a file name from the given archive name. The file extension suffix will be appended according to what is * already present. * <br> * E.g. if the compressor uses the file extension "gz", the archiver "tar", and passed argument is "archive.tar", * the returned value will be "archive.tar.gz". * * @param archive the existing archive file name * @return the normalized archive file name including the correct file name extension */ private String getArchiveFileName(String archive) { String fileExtension = getFilenameExtension(); if (archive.endsWith(fileExtension)) { return archive; } else if (archive.endsWith(archiver.getFilenameExtension())) { return archive + compressor.getFilenameExtension(); } else { return archive + fileExtension; } }
@Override public File create(String archive, File destination, File source) throws IOException { return create(archive, destination, IOUtils.filesContainedIn(source)); }