// Decompiled by DJ v3.12.12.96 Copyright 2011 Atanas Neshkov  Date: 08/10/2012 8:47:46
// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   EZIPImageLoader.java

package project;

import java.io.*;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.ImageIcon;

// Referenced classes of package project:
//            AccederADatos

public class EZIPImageLoader
{

    public EZIPImageLoader()
    {
        vectorFicherosModificados = new Vector();
        try
        {
            getPictureNamesFromAllZips();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    private byte[] readStream(InputStream stream, long sizeIfKnown)
        throws IOException
    {
        byte data[] = new byte[sizeIfKnown <= 0L ? 0x19000 : (int)sizeIfKnown + 10];
        int r;
        for(int allbytesread = 0; stream.available() > 0; allbytesread += r)
            r = stream.read(data, allbytesread, Math.min(10240, data.length - allbytesread));

        return data;
    }

    public ImageIcon[] getPicturesFromZIP(File zipFile, String pictureNames[])
        throws IOException
    {
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
        ZipEntry entry = null;
        Vector vector = new Vector();
        do
        {
            if((entry = zis.getNextEntry()) == null)
                break;
            String entryName = entry.getName();
            boolean toLoadThis = false;
            String pictureName = null;
            int i = pictureNames.length - 1;
            do
            {
                if(i <= -1)
                    break;
                if(entryName.endsWith(pictureNames[i]))
                {
                    toLoadThis = true;
                    pictureName = pictureNames[i];
                    break;
                }
                i--;
            } while(true);
            if(toLoadThis)
            {
                InputStream is = null;
                is = new BufferedInputStream(zis);
                byte imageBytes[] = readStream(is, entry.getSize());
                vector.add(new ImageIcon(imageBytes, pictureName));
            }
        } while(true);
        zis.close();
        return (ImageIcon[])(ImageIcon[])vector.toArray(new ImageIcon[vector.size()]);
    }

    public void getPictureNamesFromAllZips()
        throws IOException
    {
        vectorFicherosModificados = new Vector();
        ZipInputStream zis;
        for(Iterator iterator = AccederADatos.mapaFicherosZip.values().iterator(); iterator.hasNext(); zis.close())
        {
            File zipFile = (File)iterator.next();
            zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
            for(ZipEntry entry = null; (entry = zis.getNextEntry()) != null;)
            {
                String entryName = entry.getName();
                vectorFicherosModificados.add(entryName);
            }

        }

        AccederADatos.vectorFicherosModificados = vectorFicherosModificados;
    }

    public static final int MAX_IMAGE_SIZE = 0x19000;
    public static final int MAX_PARTIAL_SIZE = 10240;
    public static final int OFFSET_SIZE = 10;
    Vector vectorFicherosModificados;
}