How to extract files from a 7-zip stream in Java without saving it to your hard drive?

I want to extract some files from a stream with 7-zip byte, it cannot be stored on the hard drive, so I can not use the RandomAccessFile class, I read the sevenzipjbinding source code , it also unpacks a file with some closed source things, such as lib7-Zip- JBinding.so who wrote in another language. And the official SevenZip package method

SevenZip.Compression.LZMA.Decoder.Code(java.io.InputStream inStream,java.io.OutputStream outStream,long outSize,ICompressProgressInfo progress)

can only unzip a single file.

So how could I unzip a stream with 7 zip bytes with pure Java?

Do all the guys have a solution?

Sorry for my poor English, and I'm waiting for your answers online.

+8
java 7zip
source share
1 answer

Commons compress 1.6 and higher supports 7z format processing. Give it a try.

Link:

http://commons.apache.org/proper/commons-compress/index.html

Example:

  SevenZFile sevenZFile = new SevenZFile(new File("test-documents.7z")); SevenZArchiveEntry entry = sevenZFile.getNextEntry(); while(entry!=null){ System.out.println(entry.getName()); FileOutputStream out = new FileOutputStream(entry.getName()); byte[] content = new byte[(int) entry.getSize()]; sevenZFile.read(content, 0, content.length); out.write(content); out.close(); entry = sevenZFile.getNextEntry(); } sevenZFile.close(); 
+9
source share

All Articles