I am trying to remove the PAX file which automatically gets added while decompressing the tar file. This issue does not occur when decompression takes place using command prompt, but using 7zip utility. I am using the following code for creating the tar file. Please let me know if there is a suitable approach to stop the removal of PAX file when performing the decompression of tar file.
public class GZipUtils {
public static void createTarGZip(String sourceDir, String destination) throws IOException {
Path source = Paths.get(sourceDir);
try (OutputStream fOut = Files.newOutputStream(Paths.get(destination));
BufferedOutputStream buffOut = new BufferedOutputStream(fOut);
GzipCompressorOutputStream gzOut = new GzipCompressorOutputStream(buffOut);
TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut)) {
Files.walkFileTree(source, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) {
if (attributes.isSymbolicLink()) {
return FileVisitResult.CONTINUE;
}
Path targetFile = source.relativize(file);
try {
tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
TarArchiveEntry tarEntry = new TarArchiveEntry(file.toFile(), targetFile.toString());
tOut.putArchiveEntry(tarEntry);
Files.copy(file, tOut);
tOut.closeArchiveEntry();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
return FileVisitResult.CONTINUE;
}
});
tOut.finish();
}
}
}