Skip to content

Commit

Permalink
Merge pull request #126 from ie3-institute/ck/#125-largeFileCompression
Browse files Browse the repository at this point in the history
Allow usage of POSIX tar-extension
  • Loading branch information
t-ober authored Aug 17, 2021
2 parents 7d83e0e + c04a4de commit 6be0cdb
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/main/java/edu/ie3/util/io/FileIOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ private static File validateOutputFileName(

/**
* Compress all the files present in the provided directory and returns a boolean value denoting
* success or failure.
* success or failure. This method uses the POSIX extension to compress large files and those with
* big numbers.
*
* @param dirName path of the directory that should be compressed
* @param validatedOutputFile validated output file (target archive file)
Expand All @@ -258,6 +259,24 @@ private static File validateOutputFileName(
*/
private static boolean compressDir(final Path dirName, File validatedOutputFile)
throws FileException {
return compressDir(dirName, validatedOutputFile, true);
}

/**
* Compress all the files present in the provided directory and returns a boolean value denoting
* success or failure.
*
* @param dirName path of the directory that should be compressed
* @param validatedOutputFile validated output file (target archive file)
* @param usePosixExtension Use the POSIX extension for large files and big numbers
* @return a boolean which is either true on success or false otherwise
* @throws FileException If unable to write to the output stream
* @see <a href="https://ftp.gnu.org/old-gnu/Manuals/tar-1.12/html_node/tar_117.html">GNU POSIX
* tar</a>
*/
private static boolean compressDir(
final Path dirName, File validatedOutputFile, boolean usePosixExtension)
throws FileException {
Path validatedOutputFileName;

validatedOutputFileName = validatedOutputFile.toPath();
Expand All @@ -268,6 +287,12 @@ private static boolean compressDir(final Path dirName, File validatedOutputFile)
GzipCompressorOutputStream gzipOutputStream =
new GzipCompressorOutputStream(bufferedOutputStream);
TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream(gzipOutputStream)) {
if (usePosixExtension) {
/* Prepare to write big and long files */
tarOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
tarOutputStream.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
}

Files.walkFileTree(
dirName,
new SimpleFileVisitor<Path>() {
Expand Down

0 comments on commit 6be0cdb

Please sign in to comment.