Class ArchiveUtils


  • @Internal
    public class ArchiveUtils
    extends Object
    Utilities related to operations on archives.
    • Method Detail

      • compressFiles

        public static void compressFiles​(@NotNull
                                         @NotNull ArchiverType archiverType,
                                         @NotNull
                                         @NotNull Iterable<File> sourceFiles,
                                         @NotNull
                                         @NotNull File archiveFile,
                                         @Nullable
                                         @Nullable File baseDirectory)
                                  throws IOException
        Compresses multiple files into a single archive. The output archive file will be created - it can't exist before calling this method.
        Parameters:
        archiverType - Type of archiver that will be used to package the files.
        sourceFiles - Files to archive. Each file must exist.
        archiveFile - Archive file to create. Must not exist.
        baseDirectory - Optional argument: base directory of all the files to compress. If given, all file paths in the resulting archive will be calculated relatively to this directory. Must exist. If skipped, all source files will be placed in the archive root.
        Throws:
        IOException - if any IO operation fails (e.g. insufficient permissions to create new file)
        IllegalArgumentException - if passed arguments do not meet requirements
      • extractArchive

        public static void extractArchive​(@NotNull
                                          @NotNull ArchiverType archiverType,
                                          @NotNull
                                          @NotNull File archiveFile,
                                          @NotNull
                                          @NotNull File destinationDirectory)
                                   throws IOException
        Extracts an archive contents into the provided destination directory.
        Parameters:
        archiverType - Type of archiver that will be used to extract archive files.
        archiveFile - Archive file. Must exists.
        destinationDirectory - Directory to which the content of the archive should be copied. Must exist.
        Throws:
        IOException - if any IO operation fails (e.g. insufficient permissions to create new file)
        IllegalArgumentException - if passed arguments do not meet requirements