/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2008, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.virtual.spi.zip.jzipfile;

import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;

import org.jboss.jzipfile.Zip;
import org.jboss.jzipfile.ZipCatalog;
import org.jboss.virtual.spi.zip.ZipEntry;
import org.jboss.virtual.spi.zip.ZipEntryProvider;
import org.jboss.virtual.VFSUtils;

/**
 * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
 */
public class JZipFileZipEntryProvider implements ZipEntryProvider
{
   private InputStream copy;
   private List<org.jboss.jzipfile.ZipEntry> entries;
   private int index;
   private int size;

   public JZipFileZipEntryProvider(InputStream is) throws IOException
   {
      if (is == null)
         throw new IllegalArgumentException("Null input stream");

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      VFSUtils.copyStreamAndClose(is, baos);
      copy = new ByteArrayInputStream(baos.toByteArray());

      ZipCatalog catalog = Zip.readCatalog(is);
      entries = new ArrayList<org.jboss.jzipfile.ZipEntry>(catalog.allEntries());
      size = entries.size();
   }

   public ZipEntry getNextEntry() throws IOException
   {
      if (index >= size)
         return null;

      org.jboss.jzipfile.ZipEntry entry = entries.get(index++);
      return new JZipFileZipEntry(entry);
   }

   public InputStream currentStream() throws IOException
   {
      return Zip.openEntry(copy, entries.get(index));
   }
}
@@ -1166,37 +1166,20 @@
 java.io.
-ByteArrayOutputStream
+File
 ;%0D%0Aimpor
@@ -1188,27 +1188,23 @@
 java.io.
-ByteArrayIn
+FileOut
 putStrea
@@ -1228,41 +1228,16 @@
 til.
-ArrayList;%0D%0Aimport java.util.List
+Iterator
 ;%0D%0A%0D
@@ -1605,41 +1605,15 @@
 te I
-nputStream copy;%0D%0A   private List
+terator
 %3Corg
@@ -1663,17 +1663,21 @@
 ate 
-int index
+File tempFile
 ;%0D%0A 
@@ -1690,16 +1690,43 @@
 ate 
-int size
+org.jboss.jzipfile.ZipEntry current
 ;%0D%0A%0D
@@ -1901,25 +1901,93 @@
 %0D%0A      
-ByteArray
+final File tempFile = File.createTempFile(%22jzfzep%22, %22zip%22);%0D%0A      final File
 OutputSt
@@ -1991,18 +1991,16 @@
 tStream 
-ba
 os = new
@@ -2000,25 +2000,20 @@
 s = new 
-ByteArray
+File
 OutputSt
@@ -2017,16 +2017,24 @@
 tStream(
+tempFile
 );%0D%0A    
@@ -2071,75 +2071,13 @@
 is, 
-ba
 os);%0D
-%0A      copy = new ByteArrayInputStream(baos.toByteArray());%0D
 %0A%0D%0A 
@@ -2118,18 +2118,24 @@
 Catalog(
-is
+tempFile
 );%0D%0A    
@@ -2150,102 +2150,72 @@
 s = 
-new ArrayList%3Corg.jboss.jzipfile.ZipEntry%3E(catalog.allEntries());%0D%0A      size = entries.size()
+catalog.allEntries().iterator();%0D%0A      this.tempFile = tempFile
 ;%0D%0A 
@@ -2295,82 +2295,66 @@
 if (
-index %3E= size)%0D%0A         return null;%0D%0A%0D%0A      org.jboss.jzipf
+entries.hasNext()) %7B%0D%0A         return new JZipF
 ile
-.
 ZipEntry
  ent
@@ -2353,14 +2353,16 @@
 ntry
- 
+(curr
 ent
-ry
  = e
@@ -2372,64 +2372,93 @@
 ies.
-get(index++);%0D%0A      return new JZipFileZipEntry(entry);
+next());%0D%0A      %7D else %7B%0D%0A         tempFile.delete();%0D%0A         return null;%0D%0A      %7D
 %0D%0A  
@@ -2558,32 +2558,25 @@
 try(
-copy, entries.get(index)
+tempFile, current
 );%0D%0A

Fix incorrect jzipfile API usage