when i tar a file its throw exception as "is too long ( > 100 bytes) TarArchiveOutputStream". kindly guide me to insert setLongFileMode(TarOutputStream.LONGFILE_GNU); in this program.
private static void zipFilesRecursively(File baseDir, File source,TarArchiveOutputStream out) throws IOException {
if (source.isFile()) {
System.out.println("Adding File: "+ baseDir.toURI().relativize(source.toURI()).getPath());
FileInputStream fi = new FileInputStream(source);
BufferedInputStream sourceStream = new BufferedInputStream(fi,BUFFER);
TarArchiveEntry entry = new TarArchiveEntry(source, baseDir.getParentFile().toURI().relativize(source.toURI()).getPath());
int count;
byte data[] = new byte[BUFFER];
while ((count = sourceStream.read(data, 0, BUFFER)) != -1) {
out.write(data, 0, count);
}
sourceStream.close();
out.closeArchiveEntry();
} else {
if (source.listFiles() != null) {
if (source.listFiles().length == 0) {
System.out.println("Adding Empty Folder: "+ baseDir.toURI().relativize(source.toURI()).getPath());
TarArchiveEntry entry = new TarArchiveEntry(source, baseDir.getParentFile().toURI().relativize(source.toURI()).getPath());
out.putArchiveEntry(entry);
out.closeArchiveEntry();
}
for (File file : source.listFiles())
zipFilesRecursively(baseDir, file, out);
Look at this: http://commons.apache.org/proper/commons-compress/tar.html#Long_File_Names
You need to set format to posix before stream usage:
TarArchiveOutputStream stream = new TarArchiveOutputStream(...)
stream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With