public final class DirectoryArchiverUtil extends Object
The functionality implemented in this class is rudimentary at this time, and does not support:
/project/data/source
into a file
/project/data/source.zip
, use the createZipArchiveOfDirectory(String, File, String)
as:
DirectoryArchiverUtil.createJarArchiveOfDirectory("/project/data/source", "/project/data/source.zip", null);
This will archive all the contents of the source folder recursively in the zip file created. Immediate children of the source folder will be at the root of the zip file. The current implementation does not traverse down symbolic links, and they will be excluded.
DirectoryArchiverUtil.createJarArchiveOfDirectory("/project/data/source", "/project/data/source.zip", "test/one");
This will cause any files or directories which were immediate children of the source folder to appear nested under
directories test/one
in the archive (or when the archive is inflated). So
/project/data/source/file.txt
will appear at test/one/file.txt
in the archive.
META-INF/MANIFEST.MF
) file is added to the archive with just the Manifest Version
property set.
To create Jar files, use the createJarArchiveOfDirectory(String, File, String)
method instead.
This class uses ideas expressed by user Gili on a StackOverflow question: How to use JarOutputStream to create a JAR file?
Modifier and Type | Method and Description |
---|---|
static void |
createGZippedTarArchiveOfDirectory(String archiveFile,
File srcDirectory,
String rootPathPrefix)
Create a GZipped tar archive with all the contents of the directory.
|
static void |
createJarArchiveOfDirectory(String archiveFile,
File srcDirectory,
String rootPathPrefix)
Create a Jar archive with all the contents of the directory.
|
static void |
createTarArchiveOfDirectory(String archiveFile,
File srcDirectory,
String rootPathPrefix)
Create a tar archive with all the contents of the directory.
|
static void |
createZipArchiveOfDirectory(String archiveFile,
File srcDirectory,
String rootPathPrefix)
Create a zip archive with all the contents of the directory.
|
public static void createZipArchiveOfDirectory(String archiveFile, File srcDirectory, String rootPathPrefix) throws IOException
archiveFile
- The final archive file location. The file location must be writable.srcDirectory
- The source directory.rootPathPrefix
- The root prefix. Multiple directory parts should be separated by /
.IOException
- Exception reading the source directory or writing to the destination file.public static void createJarArchiveOfDirectory(String archiveFile, File srcDirectory, String rootPathPrefix) throws IOException
archiveFile
- The final archive file location. The file location must be writable.srcDirectory
- The source directory.rootPathPrefix
- The root prefix. Multiple directory parts should be separated by /
.IOException
- Exception reading the source directory or writing to the destination file.public static void createTarArchiveOfDirectory(String archiveFile, File srcDirectory, String rootPathPrefix) throws IOException
archiveFile
- The final archive file location. The file location must be writable.srcDirectory
- The source directory.rootPathPrefix
- The root prefix. Multiple directory parts should be separated by /
.IOException
- Exception reading the source directory or writing to the destination file.public static void createGZippedTarArchiveOfDirectory(String archiveFile, File srcDirectory, String rootPathPrefix) throws IOException
archiveFile
- The final archive file location. The file location must be writable.srcDirectory
- The source directory.rootPathPrefix
- The root prefix. Multiple directory parts should be separated by /
.IOException
- Exception reading the source directory or writing to the destination file.Copyright © 2016-2016 Development Entropy (deventropy.org) Contributors