Package adams.core.io

Class RarUtils


  • public class RarUtils
    extends Object
    A helper class for RAR-file related tasks.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Field Detail

      • LOGGER

        protected static Logger LOGGER
        for logging errors.
    • Constructor Detail

      • RarUtils

        public RarUtils()
    • Method Detail

      • decompress

        public static List<File> decompress​(File input,
                                            File outputDir)
        Unrars the files in a RAR file. Does not recreate the directory structure stored in the RAR file.
        Parameters:
        input - the RAR file to unrar
        outputDir - the directory where to store the extracted files
        Returns:
        the successfully extracted files
      • decompress

        public static List<File> decompress​(File input,
                                            File outputDir,
                                            boolean createDirs)
        Unrars the files in a RAR file.
        Parameters:
        input - the RAR file to unrar
        outputDir - the directory where to store the extracted files
        createDirs - whether to re-create the directory structure from the RAR file
        Returns:
        the successfully extracted files
      • decompress

        public static List<File> decompress​(File input,
                                            File outputDir,
                                            boolean createDirs,
                                            BaseRegExp match,
                                            boolean invertMatch)
        Unrars the files in a RAR file. Files can be filtered based on their filename, using a regular expression (the matching sense can be inverted).
        Parameters:
        input - the RAR file to unrar
        outputDir - the directory where to store the extracted files
        createDirs - whether to re-create the directory structure from the RAR file
        match - the regular expression that the files are matched against
        invertMatch - whether to invert the matching sense
        Returns:
        the successfully extracted files
      • decompress

        public static List<File> decompress​(File input,
                                            File outputDir,
                                            boolean createDirs,
                                            BaseRegExp match,
                                            boolean invertMatch,
                                            int bufferSize)
        Unrars the files in a RAR file. Files can be filtered based on their filename, using a regular expression (the matching sense can be inverted).
        Parameters:
        input - the RAR file to unrar
        outputDir - the directory where to store the extracted files
        createDirs - whether to re-create the directory structure from the RAR file
        match - the regular expression that the files are matched against
        invertMatch - whether to invert the matching sense
        bufferSize - the buffer size to use
        Returns:
        the successfully extracted files
      • decompress

        public static List<File> decompress​(File input,
                                            File outputDir,
                                            boolean createDirs,
                                            BaseRegExp match,
                                            boolean invertMatch,
                                            int bufferSize,
                                            MessageCollection errors)
        Unrars the files in a RAR file. Files can be filtered based on their filename, using a regular expression (the matching sense can be inverted).
        Parameters:
        input - the RAR file to unrar
        outputDir - the directory where to store the extracted files
        createDirs - whether to re-create the directory structure from the RAR file
        match - the regular expression that the files are matched against
        invertMatch - whether to invert the matching sense
        bufferSize - the buffer size to use
        errors - for storing potential errors
        Returns:
        the successfully extracted files
      • decompress

        public static boolean decompress​(File input,
                                         String archiveFile,
                                         File output)
        Unrars the specified file from a RAR file. Does not create any directories in case the parent directories of "output" don't exist yet.
        Parameters:
        input - the RAR file to unrar
        archiveFile - the file from the archive to extract
        output - the name of the output file
        Returns:
        whether file was successfully extracted
      • decompress

        public static boolean decompress​(File input,
                                         String archiveFile,
                                         File output,
                                         boolean createDirs)
        Unrars the specified file from a RAR file.
        Parameters:
        input - the RAR file to unrar
        archiveFile - the file from the archive to extract
        output - the name of the output file
        createDirs - whether to create the directory structure represented by output file
        Returns:
        whether file was successfully extracted
      • decompress

        public static boolean decompress​(File input,
                                         String archiveFile,
                                         File output,
                                         boolean createDirs,
                                         int bufferSize,
                                         MessageCollection errors)
        Unrars the specified file from a RAR file.
        Parameters:
        input - the RAR file to unrar
        archiveFile - the file from the archive to extract
        output - the name of the output file
        createDirs - whether to create the directory structure represented by output file
        bufferSize - the buffer size to use
        errors - for storing potential errors
        Returns:
        whether file was successfully extracted
      • listFiles

        public static List<File> listFiles​(File input)
        Lists the files stored in the RAR file. Lists directories automatically.
        Parameters:
        input - the RAR file to obtain the file list from
        Returns:
        the stored files
      • listFiles

        public static List<File> listFiles​(File input,
                                           boolean listDirs)
        Lists the files stored in the RAR file.
        Parameters:
        input - the RAR file to obtain the file list from
        listDirs - whether to include directories in the list
        Returns:
        the stored files
      • isRarCompressed

        public static boolean isRarCompressed​(File file)
        Checks whether the file is rar compressed. See: https://en.wikipedia.org/wiki/RAR_(file_format)
        Parameters:
        file - the file to inspect
        Returns:
        true if gzip
      • isRarCompressed

        public static boolean isRarCompressed​(byte[] data)
        Checks whether the array is rar compressed. See: https://en.wikipedia.org/wiki/RAR_(file_format)
        Parameters:
        data - the data to inspect
        Returns:
        true if gzip