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