1 /* |
1 /* |
2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
112 * Notice the fact that every jar file contains at least the manifest file, so when |
112 * Notice the fact that every jar file contains at least the manifest file, so when |
113 * we say "jar file containing only class file", we don't include that file. |
113 * we say "jar file containing only class file", we don't include that file. |
114 */ |
114 */ |
115 |
115 |
116 out.println(jmi.getJarFileKind().getMarkerChar() + " " + filename); |
116 out.println(jmi.getJarFileKind().getMarkerChar() + " " + filename); |
117 for (Iterator<String> iter = index.iterator(); iter.hasNext(); ) { |
117 for (String entry : index) { |
118 out.println(iter.next()); |
118 out.println(entry); |
119 } |
119 } |
120 |
120 |
121 } |
121 } |
122 out.flush(); |
122 out.flush(); |
123 out.close(); |
123 out.close(); |
169 |
169 |
170 /* |
170 /* |
171 * A hashmap contains a mapping from the prefix string to |
171 * A hashmap contains a mapping from the prefix string to |
172 * a hashset which contains a set of the second level of prefix string. |
172 * a hashset which contains a set of the second level of prefix string. |
173 */ |
173 */ |
174 private HashMap<String, HashSet<String>> knownPrefixMap = new |
174 private HashMap<String, HashSet<String>> knownPrefixMap = new HashMap<>(); |
175 HashMap<String, HashSet<String>>(); |
|
176 |
175 |
177 /* |
176 /* |
178 * We add maximum 5 second level entries to "sun", "java" and |
177 * We add maximum 5 second level entries to "sun", "java" and |
179 * "javax" entries. Tune this parameter to get a balance on the |
178 * "javax" entries. Tune this parameter to get a balance on the |
180 * cold start and footprint. |
179 * cold start and footprint. |
193 /* Returns a HashSet contains the meta index string. */ |
192 /* Returns a HashSet contains the meta index string. */ |
194 HashSet<String> getMetaIndex() { |
193 HashSet<String> getMetaIndex() { |
195 if (indexSet == null) { |
194 if (indexSet == null) { |
196 synchronized(this) { |
195 synchronized(this) { |
197 if (indexSet == null) { |
196 if (indexSet == null) { |
198 indexSet = new HashSet<String>(); |
197 indexSet = new HashSet<>(); |
199 Enumeration entries = jar.entries(); |
198 Enumeration<JarEntry> entries = jar.entries(); |
200 boolean containsOnlyClass = true; |
199 boolean containsOnlyClass = true; |
201 boolean containsOnlyResource = true; |
200 boolean containsOnlyResource = true; |
202 while (entries.hasMoreElements()) { |
201 while (entries.hasMoreElements()) { |
203 JarEntry entry = (JarEntry) entries.nextElement(); |
202 JarEntry entry = entries.nextElement(); |
204 String name = entry.getName(); |
203 String name = entry.getName(); |
205 /* We only look at the non-directory entry. |
204 /* We only look at the non-directory entry. |
206 MANIFEST file is also skipped. */ |
205 MANIFEST file is also skipped. */ |
207 if (entry.isDirectory() |
206 if (entry.isDirectory() |
208 || name.equals("META-INF/MANIFEST.MF")) { |
207 || name.equals("META-INF/MANIFEST.MF")) { |
336 } |
335 } |
337 |
336 |
338 /* Iterate through the hash map, add the second level package names |
337 /* Iterate through the hash map, add the second level package names |
339 * to the indexSet if has any. |
338 * to the indexSet if has any. |
340 */ |
339 */ |
341 for (Iterator<String> keysIterator = knownPrefixMap.keySet().iterator(); |
340 for (String key : knownPrefixMap.keySet()) { |
342 keysIterator.hasNext();) { |
|
343 String key = keysIterator.next(); |
|
344 HashSet<String> pkgSetStartsWithKey = knownPrefixMap.get(key); |
341 HashSet<String> pkgSetStartsWithKey = knownPrefixMap.get(key); |
345 int setSize = pkgSetStartsWithKey.size(); |
342 int setSize = pkgSetStartsWithKey.size(); |
346 |
343 |
347 if (setSize == 0) { |
344 if (setSize == 0) { |
348 continue; |
345 continue; |
351 indexSet.add(key + "/"); |
348 indexSet.add(key + "/"); |
352 } else { |
349 } else { |
353 /* If the set contains less than MAX_PKGS_WITH_KNOWN_PREFIX, add |
350 /* If the set contains less than MAX_PKGS_WITH_KNOWN_PREFIX, add |
354 * them to the indexSet of the MetaIndex object. |
351 * them to the indexSet of the MetaIndex object. |
355 */ |
352 */ |
356 for (Iterator<String> secondPkgElements = pkgSetStartsWithKey.iterator(); |
353 for (String secondPkgElement : pkgSetStartsWithKey) { |
357 secondPkgElements.hasNext();) { |
354 indexSet.add(key + "/" + secondPkgElement); |
358 indexSet.add(key + "/" + secondPkgElements.next()); |
|
359 } |
355 } |
360 } |
356 } |
361 } // end the outer "for" |
357 } // end the outer "for" |
362 } |
358 } |
363 |
359 |