Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><a href="http://docs.oracle.com/javase/1.5.0/docs/api/index.html?java/util/zip/ZipEntry.html" rel="nofollow noreferrer"><code>ZipInputStream.read()</code></a> would read x number of bytes from the <code>ZipFileEntry</code>, unzip them and give you the unzipped bytes.</li> <li>Use any of the methods <a href="http://ostermiller.org/convert_java_outputstream_inputstream.html" rel="nofollow noreferrer">here</a> to create an in/out stream.</li> <li>Give that <em>in/out stream</em> as <code>InputStream</code> to your parser.</li> <li>Start writing unzipped data to in/out stream (now treated as <code>OutputStream</code>).</li> <li>So you're now reading chunks of data from zip file, unzipping them and passing them to the parser.</li> </ul> <p>PS:</p> <ol> <li>If the zip file contains multiple files see this: <a href="https://stackoverflow.com/questions/1533253/extracting-contents-of-zipfile-entries-when-read-from-byte-java">extracting contents of ZipFile entries when read from byte[] (Java)</a>, you'll have to put in a check such that you know when you reach end of an entry.</li> <li>I donno much of SAX parser but assume that it would parse the file in this manner (when given in chunks).</li> </ol> <p>--- edit ---</p> <p>Here is what I meant:</p> <pre><code>import java.io.File; import java.io.InputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class Main { static class MyRunnable implements Runnable { private InputStream xmlStream; private SAXParser sParser; public MyRunnable(SAXParser p, InputStream is) { sParser = p; xmlStream = is; } public void run() { try { sParser.parse(xmlStream, new DefaultHandler() { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { System.out.println("\nStart Element :" + qName); } public void endElement(String uri, String localName, String qName) throws SAXException { System.out.println("\nEnd Element :" + qName); } }); System.out.println("Done parsing.."); } catch (Exception e) { e.printStackTrace(); } } } final static int BUF_SIZE = 5; public static void main(String argv[]) { try { SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); ZipFile zip = new ZipFile(new File("D:\\Workspaces\\Indigo\\Test\\performance.zip")); Enumeration&lt;? extends ZipEntry&gt; entries = zip.entries(); while (entries.hasMoreElements()) { // in stream for parser.. PipedInputStream xmlStream = new PipedInputStream(); // out stream attached to in stream above.. we would read from zip file and write to this.. // thus passing whatever we write to the parser.. PipedOutputStream out = new PipedOutputStream(xmlStream); // Parser blocks in in stream, so put him on a different thread.. Thread parserThread = new Thread(new Main.MyRunnable(saxParser, xmlStream)); parserThread.start(); ZipEntry entry = entries.nextElement(); System.out.println("\nOpening zip entry: " + entry.getName()); InputStream unzippedStream = zip.getInputStream(entry); byte buf[] = new byte[BUF_SIZE]; int bytesRead = 0; while ((bytesRead = unzippedStream.read(buf)) &gt; 0) { // write to err for different color in eclipse.. System.err.write(buf, 0, bytesRead); out.write(buf, 0, bytesRead); Thread.sleep(150); // theatrics... } out.flush(); // give parser a couple o seconds to catch up just in case there is some IO lag... parserThread.join(2000); unzippedStream.close(); out.close(); xmlStream.close(); } } catch (Exception e) { e.printStackTrace(); } } } </code></pre>
    singulars
    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. This table or related slice is empty.
    1. VO
      singulars
      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