Class ArchiveUtils


  • public class ArchiveUtils
    extends Object
    Author:
    Adam Gibson
    • Constructor Detail

      • ArchiveUtils

        protected ArchiveUtils()
    • Method Detail

      • unzipFileTo

        public static void unzipFileTo​(String file,
                                       String dest)
                                throws IOException
        Extracts all files from the archive to the specified destination.
        Note: Logs the path of all extracted files by default. Use unzipFileTo(String, String, boolean) if logging is not desired.
        Can handle .zip, .jar, .tar.gz, .tgz, .tar, and .gz formats. Format is interpreted from the filename
        Parameters:
        file - the file to extract the files from
        dest - the destination directory. Will be created if it does not exist
        Throws:
        IOException - If an error occurs accessing the files or extracting
      • unzipFileTo

        public static void unzipFileTo​(String file,
                                       String dest,
                                       boolean logFiles)
                                throws IOException
        Extracts all files from the archive to the specified destination, optionally logging the extracted file path.
        Can handle .zip, .jar, .tar.gz, .tgz, .tar, and .gz formats. Format is interpreted from the filename
        Parameters:
        file - the file to extract the files from
        dest - the destination directory. Will be created if it does not exist
        logFiles - If true: log the path of every extracted file; if false do not log
        Throws:
        IOException - If an error occurs accessing the files or extracting
      • tarListFiles

        public static List<String> tarListFiles​(File tarFile)
                                         throws IOException
        List all of the files and directories in the specified tar.gz file
        Parameters:
        tarFile - A .tar file
        Returns:
        List of files and directories
        Throws:
        IOException
      • tarGzListFiles

        public static List<String> tarGzListFiles​(File tarGzFile)
                                           throws IOException
        List all of the files and directories in the specified tar.gz file
        Parameters:
        tarGzFile - A tar.gz file
        Returns:
        List of files and directories
        Throws:
        IOException
      • zipListFiles

        public static List<String> zipListFiles​(File zipFile)
                                         throws IOException
        List all of the files and directories in the specified .zip file
        Parameters:
        zipFile - Zip file
        Returns:
        List of files and directories
        Throws:
        IOException
      • zipExtractSingleFile

        public static void zipExtractSingleFile​(File zipFile,
                                                File destination,
                                                String pathInZip)
                                         throws IOException
        Extract a single file from a .zip file. Does not support directories
        Parameters:
        zipFile - Zip file to extract from
        destination - Destination file
        pathInZip - Path in the zip to extract
        Throws:
        IOException - If exception occurs while reading/writing
      • tarGzExtractSingleFile

        public static void tarGzExtractSingleFile​(File tarGz,
                                                  File destination,
                                                  String pathInTarGz)
                                           throws IOException
        Extract a single file from a tar.gz file. Does not support directories. NOTE: This should not be used for batch extraction of files, due to the need to iterate over the entries until the specified entry is found. Use unzipFileTo(String, String) for batch extraction instead
        Parameters:
        tarGz - A tar.gz file
        destination - The destination file to extract to
        pathInTarGz - The path in the tar.gz file to extract
        Throws:
        IOException