1

I am trying to decompress a 5G text file with Apache commons compress version 1.9...

public String unZipFile(String pathFileName, String saveFilePath)  throws IOException {

    SevenZFile sevenZFile = new SevenZFile(new File(pathFileName));
    SevenZArchiveEntry entry = sevenZFile.getNextEntry();

    try {

        while (entry != null) {

            if ("deudores.txt".equals(entry.getName())) {

                Instant now = Instant.now();
                LOG.info("\tunzipping: {} -> {}/{}", pathFileName, saveFilePath, entry.getName());

                byte[] buffer = new byte[1024];
                File newFile = newFile(new File(saveFilePath), entry.getName());
                FileOutputStream fos = new FileOutputStream(newFile);
                int len;
                while ((len = sevenZFile.read(buffer)) > 0) {
                    fos.write(buffer, 0, len);
                }
                fos.close();
                LOG.info("\tunzipping done, took {} secs", now.until(Instant.now(), ChronoUnit.SECONDS));
                return saveFilePath+"/"+entry.getName();
            }
            entry = sevenZFile.getNextEntry();
        }
    } finally {
        sevenZFile.close();
    }
    return null;
}


 public File newFile(File destinationDir, String name) throws IOException {
    File destFile = new File(destinationDir, name);

    String destDirPath = destinationDir.getCanonicalPath();
    String destFilePath = destFile.getCanonicalPath();

    if (!destFilePath.startsWith(destDirPath + File.separator)) {
        throw new IOException("Entry is outside of the target dir: " + name);
    }

    return destFile;
}

I am getting only the first 1 GB

Any suggestion / alternatives ? Not a problem to swap to another library.

solved ... iteration over buffer was wrong.

Pedro Sosa
  • 39
  • 9

0 Answers0