Code example for JarFile

Methods: getEntry, getInputStream

0
    // package-private only for unit testing purpose 
    static InputSource getAutoupdateInfoInputStream (File nbmFile) throws IOException, SAXException {
        // find info.xml entry 
        JarFile jf = null;
        try { 
            jf = new JarFile (nbmFile);
        } catch (IOException ex) {
            throw new IOException("Cannot open NBM file " + nbmFile + ": " + ex, ex);
        } 
        String locale = Locale.getDefault ().toString ();
        ZipEntry entry = jf.getEntry (INFO_DIR + '/' + INFO_LOCALE + '/' + INFO_NAME + '_' + locale + INFO_EXT);
        if (entry == null) {
            entry = jf.getEntry (INFO_DIR + '/' + INFO_FILE);
        } 
        if (entry == null) {
            throw new IllegalArgumentException ("info.xml found in file " + nbmFile);
        }         
 
        return new InputSource (new BufferedInputStream (jf.getInputStream (entry)));
    } 
     
}