/* 1*/ package PFSaver; /* 2*/ /* 3*/ import java.io.BufferedInputStream; /* 4*/ import java.io.BufferedOutputStream; /* 5*/ import java.io.File; /* 6*/ import java.io.FileOutputStream; /* 7*/ import java.io.IOException; /* 8*/ import java.io.ObjectInputStream; /* 9*/ import java.io.OutputStream; /* 10*/ import java.util.Enumeration; /* 11*/ import java.util.zip.ZipEntry; /* 12*/ import java.util.zip.ZipFile; /* 13*/ /* 14*/ public class ZipDecompresser /* 15*/ { /* 16*/ private ZipFile zipfile; /* 17*/ private ObjectInputStream oin = null; /* 18*/ public static final String zipExtension = ".zip"; /* 19*/ /* 20*/ public ZipDecompresser(String zippath) throws IOException /* 21*/ { /* 22*/ zipfile = new ZipFile(zippath); /* 23*/ } /* 24*/ /* 25*/ public void decompress(String filename, String writefile) throws IOException /* 26*/ { /* 27*/ BufferedOutputStream out = null; /* 28*/ ZipEntry entry = zipfile.getEntry(filename); /* 29*/ try /* 30*/ { /* 31*/ out = new BufferedOutputStream(new FileOutputStream(writefile)); /* 32*/ decompress(out, zipfile, entry); /* 33*/ } /* 34*/ finally /* 35*/ { /* 36*/ out.close(); /* 37*/ } /* 38*/ } /* 39*/ /* 40*/ public Object decompress(ZipEntry entry) /* 41*/ throws IOException, ClassNotFoundException /* 42*/ { /* 43*/ Object obj; /* 44*/ /* 45*/ try /* 46*/ { /* 47*/ oin = new ObjectInputStream(zipfile.getInputStream(entry)); /* 48*/ obj = oin.readObject(); /* 49*/ } /* 50*/ finally /* 51*/ { /* 52*/ if(oin!=null) oin.close(); /* 53*/ } /* 54*/ /* 55*/ return obj; /* 56*/ } /* 57*/ /* 58*/ public void close() throws IOException /* 59*/ { /* 60*/ if(oin!=null) oin.close(); /* 61*/ } /* 62*/ /* 63*/ public static void decompressAll(OutputStream Aout, ZipFile zipfile) /* 64*/ throws IOException /* 65*/ { /* 66*/ Enumeration e = zipfile.entries(); /* 67*/ while(e.hasMoreElements()) /* 68*/ { /* 69*/ decompress(Aout, zipfile, ((ZipEntry)(e.nextElement()))); /* 70*/ } /* 71*/ } /* 72*/ /* 73*/ public static void decompress(OutputStream Aout, ZipFile zipfile, ZipEntry entry) /* 74*/ throws IOException /* 75*/ { /* 76*/ File file = new File(entry.getName()); /* 77*/ /* 78*/ if(entry.isDirectory()) /* 79*/ { /* 80*/ file.mkdirs(); /* 81*/ } /* 82*/ else /* 83*/ { /* 84*/ BufferedInputStream in = new BufferedInputStream( /* 85*/ zipfile.getInputStream(entry)); /* 86*/ /* 87*/ File parent = file.getParentFile(); /* 88*/ /* 89*/ if(parent!=null) /* 90*/ { /* 91*/ if(!(parent.exists())) /* 92*/ parent.mkdirs(); /* 93*/ } /* 94*/ /* 95*/ int buf; /* 96*/ while((buf=in.read())!=-1) /* 97*/ { /* 98*/ Aout.write(buf); /* 99*/ } /*100*/ in.close(); /*101*/ } /*102*/ } /*103*/ /*104*/ public static Object decompress(ZipFile zipfile, ZipEntry entry) /*105*/ throws IOException, ClassNotFoundException /*106*/ { /*107*/ ObjectInputStream oin = null; /*108*/ Object obj = null; /*109*/ /*110*/ try /*111*/ { /*112*/ oin = new ObjectInputStream(zipfile.getInputStream(entry)); /*113*/ obj = oin.readObject(); /*114*/ } /*115*/ finally /*116*/ { /*117*/ if(oin!=null) oin.close(); /*118*/ } /*119*/ /*120*/ return obj; /*121*/ } /*122*/ /*123*/ public static Object[] decompress(ZipFile zipfile) /*124*/ throws IOException, ClassNotFoundException /*125*/ { /*126*/ Object[] obj = new Object[zipfile.size()]; /*127*/ Enumeration e = zipfile.entries(); /*128*/ /*129*/ for(int i=0;e.hasMoreElements();i++) /*130*/ { /*131*/ ObjectInputStream in = null; /*132*/ try /*133*/ { /*134*/ in = new ObjectInputStream(zipfile.getInputStream( /*135*/ (ZipEntry)e.nextElement())); /*136*/ obj[i] = in.readObject(); /*137*/ } /*138*/ finally /*139*/ { /*140*/ if(in!=null) in.close(); /*141*/ } /*142*/ } /*143*/ /*144*/ return obj; /*145*/ } /*146*/ }