7zip - Decompress files with .7z extension in java -


can advice (give example) appropriate , understandable way how extract file or files .7z extension basing upon inputstream. have been examined xz java api, couldn't succeed. waiting suggestion.

this code might you.

    import java.io.file; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.io.ioexception; import java.io.randomaccessfile; import java.util.arrays;  import net.sf.sevenzipjbinding.extractoperationresult; import net.sf.sevenzipjbinding.isequentialoutstream; import net.sf.sevenzipjbinding.isevenzipinarchive; import net.sf.sevenzipjbinding.sevenzip; import net.sf.sevenzipjbinding.sevenzipexception; import net.sf.sevenzipjbinding.impl.randomaccessfileinstream; import net.sf.sevenzipjbinding.simple.isimpleinarchive; import net.sf.sevenzipjbinding.simple.isimpleinarchiveitem;  public class unzip {     public static void main(string[] args) {          randomaccessfile randomaccessfile = null;         isevenzipinarchive inarchive = null;          try {             randomaccessfile = new randomaccessfile("oclhashcat-plus-0.14.7z", "r");             inarchive = sevenzip.openinarchive(null, // autodetect archive type                     new randomaccessfileinstream(randomaccessfile));              // getting simple interface of archive inarchive             isimpleinarchive simpleinarchive = inarchive.getsimpleinterface();              system.out.println("   hash   |    size    | filename");             system.out.println("----------+------------+---------");              (final isimpleinarchiveitem item : simpleinarchive.getarchiveitems()) {                 final int[] hash = new int[] { 0 };                 if (!item.isfolder()) {                     extractoperationresult result;                      final long[] sizearray = new long[1];                     result = item.extractslow(new isequentialoutstream() {                         public int write(byte[] data) throws sevenzipexception {                              //write file                             fileoutputstream fos;                             try {                                 file file = new file(item.getpath());                                 file.getparentfile().mkdirs();                                 fos = new fileoutputstream(file);                                 fos.write(data);                                 fos.close();                              } catch (filenotfoundexception e) {                                 // todo auto-generated catch block                                 e.printstacktrace();                             } catch (ioexception e) {                                 // todo auto-generated catch block                                 e.printstacktrace();                             }                              hash[0] ^= arrays.hashcode(data); // consume data                             sizearray[0] += data.length;                             return data.length; // return amount of consumed data                         }                     });                     if (result == extractoperationresult.ok) {                         system.out.println(string.format("%9x | %10s | %s", //                                  hash[0], sizearray[0], item.getpath()));                     } else {                         system.err.println("error extracting item: " + result);                     }                 }             }         } catch (exception e) {             system.err.println("error occurs: " + e);             system.exit(1);         } {             if (inarchive != null) {                 try {                     inarchive.close();                 } catch (sevenzipexception e) {                     system.err.println("error closing archive: " + e);                 }             }             if (randomaccessfile != null) {                 try {                     randomaccessfile.close();                 } catch (ioexception e) {                     system.err.println("error closing file: " + e);                 }             }         }     } } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -