Package org.nd4j.common.util
Class ArchiveUtils
- java.lang.Object
-
- org.nd4j.common.util.ArchiveUtils
-
public class ArchiveUtils extends Object
- Author:
- Adam Gibson
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedArchiveUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidtarGzExtractSingleFile(File tarGz, File destination, String pathInTarGz)Extract a single file from a tar.gz file.static List<String>tarGzListFiles(File tarGzFile)List all of the files and directories in the specified tar.gz fileprotected static List<String>tarGzListFiles(File file, boolean isTarGz)static List<String>tarListFiles(File tarFile)List all of the files and directories in the specified tar.gz filestatic voidunzipFileTo(String file, String dest)Extracts all files from the archive to the specified destination.
Note: Logs the path of all extracted files by default.static voidunzipFileTo(String file, String dest, boolean logFiles)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.static voidzipExtractSingleFile(File zipFile, File destination, String pathInZip)Extract a single file from a .zip file.static List<String>zipListFiles(File zipFile)List all of the files and directories in the specified .zip file
-
-
-
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. UseunzipFileTo(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 fromdest- 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 fromdest- the destination directory. Will be created if it does not existlogFiles- 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
-
tarGzListFiles
protected static List<String> tarGzListFiles(File file, boolean isTarGz) throws IOException
- 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 fromdestination- Destination filepathInZip- 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. UseunzipFileTo(String, String)for batch extraction instead- Parameters:
tarGz- A tar.gz filedestination- The destination file to extract topathInTarGz- The path in the tar.gz file to extract- Throws:
IOException
-
-