import java.util.zip.*; import java.io.*; public class ZipLocate { //------------------------------------------------------------------- // static utility method to locate and return a handle to a ZIP entry //------------------------------------------------------------------- public static DataInputStream zipLocate( String filename, String zipEntryName) throws ZipException, IOException { FileInputStream fin; ZipInputStream in; ZipEntry entry; int entrySize; fin = new FileInputStream(filename); in = new ZipInputStream(fin); entry = in.getNextEntry(); while ( entry != null ) { if ( entry.getName().equals(zipEntryName) ) { break; } entry = in.getNextEntry(); } if ( ! entry.getName().equals(zipEntryName) ) { in.close(); return null; } return new DataInputStream(in); } //------------------------------------------------------------------- // static main contains self-test code. //------------------------------------------------------------------- public static void main(String[] args) { boolean OK; try { OK = ( zipLocate("test.jar", "META-INF/MANIFEST.MF") != null); } catch (ZipException zipProblem) { System.out.println(zipProblem); OK = false; } catch (IOException IOfailed) { System.out.println(IOfailed); OK = false; } String report = OK ? "OK" : "failed"; System.out.println("ZipLocate test: " + report); } } // End of Class ZipLocate