reading images from a .cbz archive
<p>I want to read images inside a .CBZ archive and store them inside an ArrayList. I have tried the following solution but it has, at least, 2 problems. </p>

<ol>
<li>I get an OutOfMemory error after adding 10-15 images to the ArrayList</li>
<li>There must be a better way of getting the images inside the ArrayList instead of writing them on a temp file and reading that again.</li>
</ol>

<p>Thanks.</p>

<pre><code>public class CBZHandler {
final int BUFFER = 2048;
ArrayList&lt;BufferedImage&gt; images = new ArrayList&lt;BufferedImage&gt;();

public void extractCBZ(ZipInputStream tis) throws IOException{
    ZipEntry entry;
    BufferedOutputStream dest = null;
    if(!images.isEmpty())
        images.clear();
    while((entry = tis.getNextEntry()) != null){
        System.out.println("Extracting " + entry.getName());
        int count;
        FileOutputStream fos =  new FileOutputStream("temp");
        dest = new BufferedOutputStream(fos,BUFFER);
        byte data[] = new byte[BUFFER];
        while ((count = tis.read(data, 0, BUFFER)) != -1) {
               dest.write(data, 0, count);
            }


        dest.flush();
        dest.close();
        BufferedImage img = ImageIO.read(new FileInputStream("temp"));
        images.add(img);

    }
    tis.close();
}
</code></pre>

<p>}</p>
