Komprimiere das Verzeichnis nach tar.gz mit Commons Compress

Ich habe ein Problem mit der Commons-Komprimierungsbibliothek, um ein tar.gz-Verzeichnis zu erstellen. Ich habe eine Verzeichnisstruktur, die wie folgt ist.

parent/
    child/
        file1.raw
        fileN.raw

Ich verwende den folgenden Code, um die Komprimierung durchzuführen. Es läuft einwandfrei ohne Ausnahmen. Wenn ich jedoch versuche, dieses tar.gz zu dekomprimieren, erhalte ich eine einzelne Datei mit dem Namen "childDirToCompress". Es hat die richtige Größe, sodass die Dateien beim Teern eindeutig aneinander angehängt wurden. Die gewünschte Ausgabe wäre ein Verzeichnis. Ich kann nicht herausfinden, was ich falsch mache. Kann ein weiser Commons-Kompressor mich auf den richtigen Weg bringen?

CreateTarGZ() throws CompressorException, FileNotFoundException, ArchiveException, IOException {
            File f = new File("parent");
            File f2 = new File("parent/childDirToCompress");

            File outFile = new File(f2.getAbsolutePath() + ".tar.gz");
            if(!outFile.exists()){
                outFile.createNewFile();
            }
            FileOutputStream fos = new FileOutputStream(outFile);

            TarArchiveOutputStream taos = new TarArchiveOutputStream(new GZIPOutputStream(new BufferedOutputStream(fos)));
            taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); 
            taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
            addFilesToCompression(taos, f2, ".");
            taos.close();

        }

        private static void addFilesToCompression(TarArchiveOutputStream taos, File file, String dir) throws IOException{
            taos.putArchiveEntry(new TarArchiveEntry(file, dir));

            if (file.isFile()) {
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
                IOUtils.copy(bis, taos);
                taos.closeArchiveEntry();
                bis.close();
            }

            else if(file.isDirectory()) {
                taos.closeArchiveEntry();
                for (File childFile : file.listFiles()) {
                    addFilesToCompression(taos, childFile, file.getName());

                }
            }
        }

Antworten auf die Frage(5)

Ihre Antwort auf die Frage