private Certificate[] getCertificates(final File container, final String entry) throws IOException { if (container.isDirectory()) { return null; } final JarFile jarFile = this.jarFiles.get(container); if (jarFile == null) { return null; } final JarEntry ent = jarFile.getJarEntry(entry); return (Certificate[]) ((ent == null) ? null : ent.getCertificates()); }
public byte[] getBytes(String className) { try { Tracer.mark(); String realName = className.replace(".", "/"); realName += ".class"; JarEntry je = jf.getJarEntry(realName); InputStream is = jf.getInputStream(je); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buff = new byte[4096]; while (is.available() > 0) { int read = is.read(buff); baos.write(buff, 0, read); } is.close(); return baos.toByteArray(); } catch (Exception e) { } finally { Tracer.unmark(); } return null; }
protected URL getResourceURL(final File file, final String resourceName) { try { JarFile jarFile = this.jarFiles.get(file); if (jarFile == null && file.isDirectory()) { final File resource = new File(file, resourceName); if (resource.exists()) { try { return AntClassLoader.FILE_UTILS.getFileURL(resource); } catch (MalformedURLException ex) { return null; } } } else { if (jarFile == null) { if (!file.exists()) { return null; } jarFile = new JarFile(file); this.jarFiles.put(file, jarFile); jarFile = this.jarFiles.get(file); } final JarEntry entry = jarFile.getJarEntry(resourceName); if (entry != null) { try { return new URL("jar:" + AntClassLoader.FILE_UTILS.getFileURL(file) + "!/" + entry); } catch (MalformedURLException ex) { return null; } } } } catch (Exception e) { final String msg = "Unable to obtain resource from " + file + ": "; this.log(msg + e, 1); System.err.println(msg); e.printStackTrace(); } return null; }
private InputStream getResourceStream(final File file, final String resourceName) { try { JarFile jarFile = this.jarFiles.get(file); if (jarFile == null && file.isDirectory()) { final File resource = new File(file, resourceName); if (resource.exists()) { return new FileInputStream(resource); } } else { if (jarFile == null) { if (!file.exists()) { return null; } jarFile = new JarFile(file); this.jarFiles.put(file, jarFile); jarFile = this.jarFiles.get(file); } final JarEntry entry = jarFile.getJarEntry(resourceName); if (entry != null) { return jarFile.getInputStream(entry); } } } catch (Exception e) { this.log( "Ignoring Exception " + e.getClass().getName() + ": " + e.getMessage() + " reading resource " + resourceName + " from " + file, 3); } return null; }