I am writing a Java program that gives a name with a name (for example:) java.lang.String, extracts and returns the corresponding record from a file src.zipin the JDK for further processing.
So far, my program works fine for any qualified name that relates to a specific source file .java; but I am having problems when the qualified name applies to the whole package (for example:) java.util.*. In this case, I want my program to return a list of all the entries in this package.
The problem is that there is no way to effectively (do this) with the utilities provided in the package java.util.zip.*! I have tried both ZipFile, ZipInputStreamand no one recognizes directories in the file src.zip! They only return records for individual source files .java!
In a code language, both:
ZipEntry entry;
ZipInputStream zip = new ZipInputStream(new FileInputStream("src.zip"));
while((entry = zip.getNextEntry()) != null)
System.out.println(entry.isDirectory());
and
Enumeration<? extends ZipEntry> zip = new ZipFile("src.zip").entries();
while (zip.hasMoreElements()) {
ZipEntry entry = zip.nextElement();
System.out.println(entry.isDirectory());
}
always returns false; no directories at all!
Even the following code is useless and just returns null(which means Not Found):
ZipFile zipfile = new ZipFile("src.zip");
zipfile.getEntry("java/util/");
A workaround is to use one of the two iterations listed above and perform an exhaustive search for the required records:
if (entry.getName().startsWith("java/util/"))
System.out.println(entry);
! src.zip ? , ZIP ( ).
Update
, src.zip Oracle JDK (, JDK-8 update-111). src.zip JDK (, JDK-7 update-80). marabu unzip -l .
, , ZIP , . , - , , Truckle , - , - ZIP.