apache commons compress using 7zip
Asked Answered
S

1

17

i am trying to use the below code that i got from apache commons compress examples webpage to create a zip file using the sevenZ classes hoping it would be faster to compress than regular java zip. this is what my code looks like

public static void main(String[] args) {
    // TODO Auto-generated method stub
    try{
    BufferedInputStream instream = new BufferedInputStream(new FileInputStream("c:/temp/test.txt"));

    SevenZOutputFile sevenZOutput = new SevenZOutputFile(new File("c:/temp/7ztest.zip"));
    SevenZArchiveEntry entry = sevenZOutput.createArchiveEntry(new File("c:/temp/test.txt"),"blah.txt");
    sevenZOutput.putArchiveEntry(entry);
    byte[] buffer = new byte[1024];
    int len;
    while ((len = instream.read(buffer)) > 0) {sevenZOutput.write(buffer, 0, len);}

    sevenZOutput.closeArchiveEntry();
    sevenZOutput.close();
    instream.close();
    }catch(IOException ioe) {
        System.out.println(ioe.toString());

    }
}

i get this error which looks so unrelated

Exception in thread "main" java.lang.NoClassDefFoundError: org.tukaani.xz.FilterOptions at java.lang.J9VMInternals.verifyImpl(Native Method) at java.lang.J9VMInternals.verify(J9VMInternals.java:93)

i have the apache packages imported

import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry; import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile;

but not sure what the org.tukaani.xz.FilterOptions is, it doesnt look like it is part of the apace commons compress. Any thoughts?

Sensuous answered 30/1, 2015 at 4:10 Comment(1)
It is worth noting that when you will decompress de file it will throw an error because you compressed it into a 7z file but the extension is .zipPhilology
T
31

EDIT 2024-03-30: There seems to be a very serious compromise in the XZ library by the maintainer. Do NOT use the dependency without first verifying that the vulnerabilities have been adressed:

CVE-2024-3094

As noted on the "Known Limitations" page at Apache Commons:

"the format requires the otherwise optional XZ for Java library."

This dependency is optional for the other formats, but you need it for 7zip.

<dependency>
  <groupId>org.tukaani</groupId>
  <artifactId>xz</artifactId>
  <version>1.5</version>
</dependency>
Talapoin answered 2/2, 2015 at 12:14 Comment(1)
PSA: The current version of Apache Commons Compression (1.14) requires version 1.6 the xz.Torrell

© 2022 - 2024 — McMap. All rights reserved.