--- Revision None +++ Revision 653337376466 @@ -0,0 +1,68 @@ +package zip.simple; + +import com.jcraft.jzlib.ZStream; +import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +/** + * @author Romain Manni-Bucau + */ +public class Main { + public static void main(String[] a) { + final String filename = "/home/rmannibucau/Bureau/openejb-core-3.1.4.jar"; + final int nTimes = 100; + + long start = 0, end = 0; + List list = new ArrayList(); + + // jdk way: jar + for (int i = 0; i < nTimes; i++) { + list.clear(); + + try { + JarInputStream jarFile = new JarInputStream(new FileInputStream(filename)); + JarEntry jarEntry; + + start = System.nanoTime(); + while ((jarEntry = jarFile.getNextJarEntry()) != null) { + if (jarEntry.getName().endsWith(".class")) { + list.add(jarEntry.getName().replaceAll("/", "\\.")); + } + } + end = System.nanoTime(); + } catch (Exception e) { + e.printStackTrace(); + } + } + System.out.println(TimeUnit.NANOSECONDS.toMillis(end - start) + " for " + list.size() + " classes "); + + // jdk way: zip + for (int i = 0; i < nTimes; i++) { + list.clear(); + + try { + ZipFile zipFile = new ZipFile(filename); + Enumeration zipEntries = zipFile.entries(); + + start = System.nanoTime(); + while (zipEntries.hasMoreElements()) { + ZipEntry entry = zipEntries.nextElement(); + if (entry.getName().endsWith(".class")) { + list.add(entry.getName().replaceAll("/", "\\.")); + } + } + end = System.nanoTime(); + } catch (Exception e) { + e.printStackTrace(); + } + } + System.out.println(TimeUnit.NANOSECONDS.toMillis(end - start) + " for " + list.size() + " classes "); + } +}