Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when i tar a file its throw exception as "is too long ( > 100 bytes) TarArchiveOutputStream"

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);
like image 836
John Avatar asked Sep 11 '15 17:09

John


1 Answers

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)
like image 150
michael nesterenko Avatar answered Oct 03 '22 09:10

michael nesterenko