I have this password protected 7z archive that can be properly opened and extracted with 7z alone. But using the code below:
byte[] PASSWORD = "secret".getBytes();
String fileName = "r:/txt.7z";
SevenZArchiveEntry entry;
try (SevenZFile arch = new SevenZFile(new File(fileName), PASSWORD)) {
while ((entry = arch.getNextEntry()) != null) {
System.out.println(entry.getName());
}
// for (var e : arch.getEntries()) {
// System.out.println(e.getName());
// }
}
causes this exception:
Exception in thread "main" java.io.IOException: Stream is not in the BZip2 format
at org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream.init(BZip2CompressorInputStream.java:252)
at org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream.<init>(BZip2CompressorInputStream.java:134)
at org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream.<init>(BZip2CompressorInputStream.java:112)
at org.apache.commons.compress.archivers.sevenz.Coders$BZIP2Decoder.decode(Coders.java:254)
at org.apache.commons.compress.archivers.sevenz.Coders.addDecoder(Coders.java:79)
at org.apache.commons.compress.archivers.sevenz.SevenZFile.buildDecoderStack(SevenZFile.java:933)
at org.apache.commons.compress.archivers.sevenz.SevenZFile.buildDecodingStream(SevenZFile.java:909)
at org.apache.commons.compress.archivers.sevenz.SevenZFile.getNextEntry(SevenZFile.java:222)
Please note, that if you uncomment for
loop and comment out while
loop, it actually prints (the sole) file name in the archive. It's getNextEntry
that triggers the exception about BZip2 format.
I wasn't able to find any bug reports concerning this problem. Of course I thought it might be incorrect password, so I changed it to some rubbish, to see the outcome, but then it gives different exception with suggestion in message, that probably the password is incorrect. So, it seems like password is definitely correct, yet I can't uncompress the file.
I have also xz-1.8.jar (org.tukaani.xz) in my classpath.
I have also tried SevenZFile
constructor with SeekableByteBuffer
, but exactly the same exception pops up.
Any clues?