use of java.net.JarURLConnection in project jdk8u_jdk by JetBrains.
the class DeleteTempJar method realMain.
public static void realMain(String[] args) throws Exception {
final File zf = File.createTempFile("deletetemp", ".jar");
zf.deleteOnExit();
try (FileOutputStream fos = new FileOutputStream(zf);
JarOutputStream jos = new JarOutputStream(fos)) {
JarEntry je = new JarEntry("entry");
jos.putNextEntry(je);
jos.write("hello, world".getBytes("ASCII"));
}
HttpServer server = HttpServer.create(new InetSocketAddress((InetAddress) null, 0), 0);
HttpContext context = server.createContext("/", new HttpHandler() {
public void handle(HttpExchange e) {
try (FileInputStream fis = new FileInputStream(zf)) {
e.sendResponseHeaders(200, zf.length());
OutputStream os = e.getResponseBody();
byte[] buf = new byte[1024];
int count = 0;
while ((count = fis.read(buf)) != -1) {
os.write(buf, 0, count);
}
} catch (Exception ex) {
unexpected(ex);
} finally {
e.close();
}
}
});
server.start();
URL url = new URL("jar:http://localhost:" + new Integer(server.getAddress().getPort()).toString() + "/deletetemp.jar!/");
JarURLConnection c = (JarURLConnection) url.openConnection();
JarFile f = c.getJarFile();
check(f.getEntry("entry") != null);
System.out.println(f.getName());
server.stop(0);
}
use of java.net.JarURLConnection in project jackrabbit-oak by apache.
the class SpringBootSupport method processDescriptors.
public static List<BundleDescriptor> processDescriptors(List<BundleDescriptor> descriptors) throws IOException {
List<BundleDescriptor> processed = Lists.newArrayList();
for (BundleDescriptor desc : descriptors) {
if (desc.getRevision() == null) {
URL u = new URL(desc.getUrl());
URLConnection uc = u.openConnection();
if (uc instanceof JarURLConnection && uc.getClass().getName().startsWith(SPRING_BOOT_PACKAGE)) {
Revision rev = new SpringBootJarRevision(((JarURLConnection) uc).getJarFile(), uc.getLastModified());
desc = new BundleDescriptor(desc.getClassLoader(), desc.getUrl(), desc.getHeaders(), rev, desc.getServices());
}
}
processed.add(desc);
}
return processed;
}
use of java.net.JarURLConnection in project sling by apache.
the class OriginalTldLocationsCache method scanJars.
/*
* Scans all JARs accessible to the webapp's classloader and its
* parent classloaders for TLDs.
*
* The list of JARs always includes the JARs under WEB-INF/lib, as well as
* all shared JARs in the classloader delegation chain of the webapp's
* classloader.
*
* Considering JARs in the classloader delegation chain constitutes a
* Tomcat-specific extension to the TLD search
* order defined in the JSP spec. It allows tag libraries packaged as JAR
* files to be shared by web applications by simply dropping them in a
* location that all web applications have access to (e.g.,
* <CATALINA_HOME>/common/lib).
*
* The set of shared JARs to be scanned for TLDs is narrowed down by
* the <tt>noTldJars</tt> class variable, which contains the names of JARs
* that are known not to contain any TLDs.
*/
private void scanJars() throws Exception {
ClassLoader webappLoader = Thread.currentThread().getContextClassLoader();
ClassLoader loader = webappLoader;
while (loader != null) {
if (loader instanceof URLClassLoader) {
URL[] urls = ((URLClassLoader) loader).getURLs();
for (int i = 0; i < urls.length; i++) {
URLConnection conn = urls[i].openConnection();
if (conn instanceof JarURLConnection) {
if (needScanJar(loader, webappLoader, ((JarURLConnection) conn).getJarFile().getName())) {
scanJar((JarURLConnection) conn, true);
}
} else {
String urlStr = urls[i].toString();
if (urlStr.startsWith(FILE_PROTOCOL) && urlStr.endsWith(JAR_FILE_SUFFIX) && needScanJar(loader, webappLoader, urlStr)) {
URL jarURL = new URL("jar:" + urlStr + "!/");
scanJar((JarURLConnection) jarURL.openConnection(), true);
}
}
}
}
loader = loader.getParent();
}
}
use of java.net.JarURLConnection in project robovm by robovm.
the class TrustedCertificateStore method list.
private String[] list(URI file) {
if ("file".equals(file.getScheme())) {
return new File(file).list();
}
if ("jar".equals(file.getScheme())) {
try {
JarURLConnection conn = (JarURLConnection) file.toURL().openConnection();
JarFile jarFile = conn.getJarFile();
String uriStr = file.toString();
if (!uriStr.endsWith("/")) {
uriStr += "/";
}
String path = uriStr.substring(uriStr.lastIndexOf('!') + 1);
if (path.startsWith("/")) {
path = path.substring(1);
}
Enumeration<JarEntry> en = jarFile.entries();
List<String> result = new ArrayList<String>();
while (en.hasMoreElements()) {
JarEntry entry = en.nextElement();
String name = entry.getName();
if (name.startsWith(path) && !name.endsWith("/")) {
int lastSlash = name.lastIndexOf('/');
if (lastSlash == path.length() - 1) {
result.add(name.substring(lastSlash + 1));
}
}
}
return result.toArray(new String[result.size()]);
} catch (IOException e) {
}
}
return null;
}
use of java.net.JarURLConnection in project robovm by robovm.
the class OldJarURLConnectionTest method test_getCertificates.
public void test_getCertificates() throws Exception {
URL u = createContent("TestCodeSigners.jar", "Test.class");
juc = (JarURLConnection) u.openConnection();
assertNull(juc.getCertificates());
JarEntry je = juc.getJarEntry();
JarFile jf = juc.getJarFile();
InputStream is = jf.getInputStream(je);
is.skip(je.getSize());
Certificate[] certs = juc.getCertificates();
assertEquals(3, certs.length);
URL invURL = createContent("InvalidJar.jar", "Test.class");
JarURLConnection juConn = (JarURLConnection) invURL.openConnection();
try {
juConn.getCertificates();
fail("IOException was not thrown.");
} catch (java.io.IOException io) {
//expected
}
}
Aggregations