Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>found the solution using 7-Zip-JBinding</p> <p>just need to use ByteArrayInputStream ,this so far worked for a small file</p> <p>pass a archive as argument to get all files inside printed</p> <p>file ExtractItemsSimple.java</p> <pre><code>import java.io.IOException; import java.io.RandomAccessFile; 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 ExtractItemsSimple { public static void main(String[] args) { RandomAccessFile randomAccessFile = null; ISevenZipInArchive inArchive = null; try { randomAccessFile = new RandomAccessFile(args[0], "r"); inArchive = SevenZip.openInArchive(null, // autodetect archive type new RandomAccessFileInStream(randomAccessFile)); ISimpleInArchive simpleInArchive = inArchive.getSimpleInterface(); for (ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) { final int[] hash = new int[] { 0 }; if (!item.isFolder()) { System.out.println(ArchieveInputStreamHandler.slurp(new ArchieveInputStreamHandler(item).getInputStream(),1000)); } } } catch (Exception e) { System.err.println("Error occurs: " + e); System.exit(1); } finally { 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); } } } } } </code></pre> <p>file ArchieveInputStreamHandler.java</p> <pre><code>import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.UnsupportedEncodingException; import net.sf.sevenzipjbinding.ISequentialOutStream; import net.sf.sevenzipjbinding.SevenZipException; import net.sf.sevenzipjbinding.simple.ISimpleInArchiveItem; public class ArchieveInputStreamHandler { private ISimpleInArchiveItem item; private ByteArrayInputStream arrayInputStream; public ArchieveInputStreamHandler(ISimpleInArchiveItem item) { this.item = item; } public InputStream getInputStream() throws SevenZipException{ item.extractSlow(new ISequentialOutStream() { @Override public int write(byte[] data) throws SevenZipException { arrayInputStream = new ByteArrayInputStream(data); return data.length; // Return amount of consumed data } }); return arrayInputStream; } //got from http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string public static String slurp(final InputStream is, final int bufferSize){ final char[] buffer = new char[bufferSize]; final StringBuilder out = new StringBuilder(); try { final Reader in = new InputStreamReader(is, "UTF-8"); try { for (;;) { int rsz = in.read(buffer, 0, buffer.length); if (rsz &lt; 0) break; out.append(buffer, 0, rsz); } } finally { in.close(); } } catch (UnsupportedEncodingException ex) { /* ... */ } catch (IOException ex) { /* ... */ } return out.toString(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload