Package adams.core.io
Class RarUtils
- java.lang.Object
-
- adams.core.io.RarUtils
-
public class RarUtils extends Object
A helper class for RAR-file related tasks.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRarUtils.DummyUnrarCallbackDummy class.
-
Constructor Summary
Constructors Constructor Description RarUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<File>decompress(File input, File outputDir)Unrars the files in a RAR file.static List<File>decompress(File input, File outputDir, boolean createDirs)Unrars the files in a RAR file.static List<File>decompress(File input, File outputDir, boolean createDirs, BaseRegExp match, boolean invertMatch)Unrars the files in a RAR file.static List<File>decompress(File input, File outputDir, boolean createDirs, BaseRegExp match, boolean invertMatch, int bufferSize)Unrars the files in a RAR file.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.static booleandecompress(File input, String archiveFile, File output)Unrars the specified file from a RAR file.static booleandecompress(File input, String archiveFile, File output, boolean createDirs)Unrars the specified file from a RAR file.static booleandecompress(File input, String archiveFile, File output, boolean createDirs, int bufferSize, MessageCollection errors)Unrars the specified file from a RAR file.static booleanisRarCompressed(byte[] data)Checks whether the array is rar compressed.static booleanisRarCompressed(File file)Checks whether the file is rar compressed.static List<File>listFiles(File input)Lists the files stored in the RAR file.static List<File>listFiles(File input, boolean listDirs)Lists the files stored in the RAR file.
-
-
-
Field Detail
-
LOGGER
protected static Logger LOGGER
for logging errors.
-
-
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 unraroutputDir- 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 unraroutputDir- the directory where to store the extracted filescreateDirs- 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 unraroutputDir- the directory where to store the extracted filescreateDirs- whether to re-create the directory structure from the RAR filematch- the regular expression that the files are matched againstinvertMatch- 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 unraroutputDir- the directory where to store the extracted filescreateDirs- whether to re-create the directory structure from the RAR filematch- the regular expression that the files are matched againstinvertMatch- whether to invert the matching sensebufferSize- 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 unraroutputDir- the directory where to store the extracted filescreateDirs- whether to re-create the directory structure from the RAR filematch- the regular expression that the files are matched againstinvertMatch- whether to invert the matching sensebufferSize- the buffer size to useerrors- 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 unrararchiveFile- the file from the archive to extractoutput- 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 unrararchiveFile- the file from the archive to extractoutput- the name of the output filecreateDirs- 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 unrararchiveFile- the file from the archive to extractoutput- the name of the output filecreateDirs- whether to create the directory structure represented by output filebufferSize- the buffer size to useerrors- 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 fromlistDirs- 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
-
-