Check the specified JAR file, and return <code>true</code> if it does
not contain any of the trigger classes.

@param jarfile The JAR file to be checked

@exception IOException if an input/output error occurs
345496
protected boolean validateJarFile(File jarfile)
        throws IOException {

        if (triggers == null)
            return (true);
        JarFile jarFile = new JarFile(jarfile);
        for (int i = 0; i < triggers.length; i++) {
            Class clazz = null;
            try {
                if (parent != null) {
                    clazz = parent.loadClass(triggers[i]);
                } else {
                    clazz = Class.forName(triggers[i]);
                }
            } catch (Throwable t) {
                clazz = null;
            }
            if (clazz == null)
                continue;
            String name = triggers[i].replace('.', '/') + ".class";
            if (log.isDebugEnabled())
                log.debug(" Checking for " + name);
            JarEntry jarEntry = jarFile.getJarEntry(name);
            if (jarEntry != null) {
                log.info("validateJarFile(" + jarfile + 
                    ") - jar not loaded. See Servlet Spec 2.3, "
                    + "section 9.7.2. Offending class: " + name);
                jarFile.close();
                return (false);
            }
        }
        jarFile.close();
        return (true);

    }
341932
public void setJarFile(IPath jarFile) {
		if (!Objects.equal(jarFile, this.jarFile)) {
			final PropertyChangeEvent event = new PropertyChangeEvent(this, ISREInstallChangedListener.PROPERTY_JAR_FILE,
					this.jarFile, jarFile);
			this.jarFile = jarFile;
			setDirty(true);
			if (getNotify()) {
				SARLRuntime.fireSREChanged(event);
			}
		}
	}
302519
public synchronized JarFile getFilteredJarFile(JarEntryFilter... filters)
            throws IOException {
        return new JarFile(this.rootFile, this.pathFromRoot, this.data, this.entries,
                filters);
    }
714118
private void jarDir(File dirOrFile2jar, JarOutputStream jos, String path)
		throws IOException {
		if (mVerbose) {
			System.out.println("checking " + dirOrFile2jar);
		}
		if (dirOrFile2jar.isDirectory()) {
			String[] dirList = dirOrFile2jar.list();
			String subPath = (path == null) ? "" : (path + dirOrFile2jar.getName() + SEP);
			if (path != null) {
				JarEntry je = new JarEntry(subPath);
				je.setTime(dirOrFile2jar.lastModified());
				jos.putNextEntry(je);
				jos.flush();
				jos.closeEntry();
			}
			for (int i = 0; i < dirList.length; i++) {
				File f = new File(dirOrFile2jar, dirList[i]);
				jarDir(f, jos, subPath);
			}
		} else if (dirOrFile2jar.exists()) {
			if (dirOrFile2jar.getCanonicalPath().equals(mDestJarName)) {
				if (mVerbose) {
					System.out.println("skipping " + dirOrFile2jar.getPath());
				}
				return;
			}

			if (mVerbose) {
				System.out.println("adding " + dirOrFile2jar.getPath());
			}
			FileInputStream fis = new FileInputStream(dirOrFile2jar);
			try {
				JarEntry entry = new JarEntry(path + dirOrFile2jar.getName());
				entry.setTime(dirOrFile2jar.lastModified());
				jos.putNextEntry(entry);
				while ((mByteCount = fis.read(mBuffer)) != -1) {
					jos.write(mBuffer, 0, mByteCount);
					if (mVerbose) {
						System.out.println("wrote " + mByteCount + " bytes");
					}
				}
				jos.flush();
				jos.closeEntry();
			} catch (IOException ioe) {
				throw ioe;
			} finally {
				fis.close();
			}
		}
	}
1244157
protected JarFile getJarFile(String jarFileUrl) throws IOException {
        if (jarFileUrl.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
            try {
                return new JarFile(ResourceUtils.toURI(jarFileUrl).getSchemeSpecificPart());
            } catch (URISyntaxException ex) {
                // Fallback for URLs that are not valid URIs (should hardly ever happen).
                return new JarFile(jarFileUrl.substring(ResourceUtils.FILE_URL_PREFIX.length()));
            }
        }
        return new JarFile(jarFileUrl);
    }
182491
public static File jarFile(Class<?> clazz) throws IOException {
        return jarFile(classFileUrl(clazz), clazz.getName().replace('.', '/') + ".class");
    }
706052
private static Class checkClass(ProtoFile protoFile, Type type, Map<String, String> mappedUniName,
            boolean isUniName) {
        String packageName = protoFile.getPackageName();
        String defaultClsName = type.getName();
        // to check if has "java_package" option and "java_outer_classname"
        List<Option> options = protoFile.getOptions();
        if (options != null) {
            for (Option option : options) {
                if (option.getName().equals(JAVA_PACKAGE_OPTION)) {
                    packageName = option.getValue().toString();
                } else if (option.getName().equals(JAVA_OUTER_CLASSNAME_OPTION)) {
                    defaultClsName = option.getValue().toString();
                }
            }
        }

        String simpleName = getProxyClassName(defaultClsName, mappedUniName, isUniName);
        String className = packageName + PACKAGE_SPLIT_CHAR + simpleName;

        Class<?> c = null;
        try {
            c = Class.forName(className);
        } catch (ClassNotFoundException e1) {
            // if class not found so should generate a new java source class.
            c = null;
        }

        return c;
    }
768728
public static JarFile getJarFile(URL url) {
		try {
			JarURLConnection urlConnection = (JarURLConnection) url.openConnection();
			return urlConnection.getJarFile();
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
260317
private boolean bufferLocalFileHeader() throws IOException {
        buffer.reset();
        JarEntry jarEntry = virtualJarInputStream.getNextJarEntry();

        if (jarEntry == null) { return false; }

        currentEntry = new ProcessedEntry(jarEntry, totalRead);
        processedEntries.add(currentEntry);


        bufferInt(ZipEntry.LOCSIG);    // Local file header signature
        bufferShort(10);               // Extraction version
        bufferShort(0);                // Flags
        bufferShort(ZipEntry.STORED);  // Compression type
        bufferInt(jarEntry.getTime()); // Entry time
        bufferInt(0);                  // CRC
        bufferInt(0);                  // Compressed size
        bufferInt(0);                  // Uncompressed size
        byte[] nameBytes = jarEntry.getName().getBytes("UTF8");
        bufferShort(nameBytes.length); // Entry name length
        bufferShort(0);                // Extra length
        buffer(nameBytes);
        return true;
    }
1266394
public static void closeQuietly(final JarFile aJarFile) {
        if (aJarFile != null) {
            try {
                aJarFile.close();
            } catch (final IOException details) {
                LOGGER.error(details.getMessage(), details);
            }
        }
    }
1038306
public static Set<Path> getDirectoriesFromJar(Path pathToJarFile) throws IOException {
        Set<Path> result = new HashSet<Path>();
        ZipFile jarfile = new ZipFile(pathToJarFile.toFile());
        try {
            final Enumeration<? extends ZipEntry> entries = jarfile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entry.isDirectory()) {
                    result.add(Paths.get(entry.getName()));
                }
            }
            jarfile.close();
        } finally {
            IOUtils.closeQuietly(jarfile);
        }
        return result;
    }
671529
public static final Map<String,JarEntry> findClassByJar(JarFile jarFile) throws IOException {
		Map<String,JarEntry> map=new HashMap<String,JarEntry>();
		if(jarFile==null)
		{
			throw new RuntimeException("jarFile is Null");
		}
		String Suffix=".class";
		Enumeration<JarEntry> jarEntries = jarFile.entries();
		while (jarEntries.hasMoreElements()) 
		{//遍历jar的实体对象
			JarEntry jarEntry = jarEntries.nextElement();
			if(jarEntry.isDirectory() || !jarEntry.getName().endsWith(Suffix))
			{
				continue;
			}
			String jarEntryName = jarEntry.getName(); // 类似：sun/security/internal/interfaces/TlsMasterSecret.class
			String className = jarEntryName.substring(0, jarEntryName.length() - Suffix.length());//sun/security/internal/interfaces/TlsMasterSecret
			//注意,jar文件里面的只能是/不能是\
			className = className.replace("/", ".");//sun.security.internal.interfaces.TlsMasterSecret
			map.put(className,jarEntry);
		}
		return map;
	}
945058
private JarFile getJarFile(String jarFileUrl) throws IOException {
        if (jarFileUrl.startsWith("file:")) {
            try {
                final URI uri = new URI(jarFileUrl.replaceAll(" ", "\\%20"));
                final String jarFileName = uri.getSchemeSpecificPart();
                logger.info("Creating new JarFile based on URI-scheme filename: {}", jarFileName);
                return new JarFile(jarFileName);
            } catch (URISyntaxException ex) {
                // Fallback for URLs that are not valid URIs (should hardly ever
                // happen).
                final String jarFileName = jarFileUrl.substring("file:".length());
                logger.info("Creating new JarFile based on alternative filename: {}", jarFileName);
                return new JarFile(jarFileName);
            }
        } else {
            logger.info("Creating new JarFile based on URI (with '!/'): {}", jarFileUrl);
            return new JarFile(jarFileUrl);
        }
    }
1291880
@Override
    protected File getFileForLastModifiedCheck() throws IOException {
        URL url = getURL();
        if (ResourceUtils.isJarURL(url)) {
            URL actualUrl = ResourceUtils.extractArchiveURL(url);
            return ResourceUtils.getFile(actualUrl, "Jar URL");
        } else {
            return getFile();
        }
    }
229884
public static JarClassLoader loadJar(File jarFile) {
		final JarClassLoader loader = new JarClassLoader();
		loader.addJar(jarFile);
		return loader;
	}
140611
@SuppressWarnings("resource")
    @Override
    @Trivial
    public void close() throws ClassSource_Exception {
        String methodName = "close";
        if ( tc.isEntryEnabled() ) {
            Tr.entry(tc, methodName, getHashText());
        }

        JarFile useJarFile = getJarFile();
        if ( (opens < 0) ||
             ((opens == 0) && (useJarFile != null)) ||
             ((opens > 0) && (useJarFile == null)) ) {

            Tr.warning(tc, "ANNO_CLASSSOURCE_JAR_STATE_BAD", getHashText(), getJarPath(), Integer.valueOf(opens));

            opens = 0;
            useJarFile = clearJarFile();
            if ( useJarFile != null ) {
                try {
                    useJarFile.close(); // throws IOException
                } catch ( IOException e ) {
                    // defect 84235:we are generating multiple Warning/Error messages for each error due to each level reporting them.
                    // Disable the following warning and defer message generation to a higher level, 
                    // preferably the ultimate consumer of the exception.
                    //Tr.warning(tc, "ANNO_CLASSSOURCE_CLOSE5_EXCEPTION", getHashText(), getJarPath());

                    String eMsg = "[ " + getHashText() + " ] Failed to close [ " + getJarPath() + " ]";
                    throw getFactory().wrapIntoClassSourceException(CLASS_NAME, methodName, eMsg, e);
                }
            }

            String eMsg = "[ " + getHashText() + " ] Close with open count [ " + opens + " ]";
            throw getFactory().newClassSourceException(eMsg);
        }

        if ( --opens == 0 ) {
            useJarFile = clearJarFile();

            try {
                useJarFile.close(); // throws IOException
            } catch ( IOException e ) {
                // defect 84235:we are generating multiple Warning/Error messages for each error due to each level reporting them.
                // Disable the following warning and defer message generation to a higher level, 
                // preferably the ultimate consumer of the exception.
                //Tr.warning(tc, "ANNO_CLASSSOURCE_CLOSE5_EXCEPTION", getHashText(), getJarPath());

                String eMsg = "[ " + getHashText() + " ] Failed to close [ " + getJarPath() + " ]";
                throw getFactory().wrapIntoClassSourceException(CLASS_NAME, methodName, eMsg, e);
            }
        }

        if ( tc.isEntryEnabled() ) {
            Tr.exit(tc, methodName, getHashText());
        }
    }
491497
protected void closeJar ()
    {
        try {
            if (_jarSource != null) {
                _jarSource.close();
            }
        } catch (Exception ioe) {
            log.warning("Failed to close jar file", "path", _source, "error", ioe);
        }
    }