use of java.net.JarURLConnection in project Openfire by igniterealtime.
the class PluginClassLoader method unloadJarFiles.
/**
* Unload any JAR files that have been cached by this plugin
*/
public void unloadJarFiles() {
for (JarURLConnection url : cachedJarFiles) {
try {
Log.info("Unloading plugin JAR file " + url.getJarFile().getName());
url.getJarFile().close();
} catch (Exception e) {
Log.error("Failed to unload JAR file", e);
}
}
}
use of java.net.JarURLConnection in project undertow by undertow-io.
the class URLResource method openConnection.
private void openConnection() {
if (!connectionOpened) {
connectionOpened = true;
URLConnection connection = null;
try {
try {
connection = url.openConnection();
} catch (IOException e) {
lastModified = null;
contentLength = null;
return;
}
if (url.getProtocol().equals("jar")) {
connection.setUseCaches(false);
URL jar = ((JarURLConnection) connection).getJarFileURL();
lastModified = new Date(new File(jar.getFile()).lastModified());
} else {
lastModified = new Date(connection.getLastModified());
}
contentLength = connection.getContentLengthLong();
} finally {
if (connection != null) {
try {
IoUtils.safeClose(connection.getInputStream());
} catch (IOException e) {
// ignore
}
}
}
}
}
use of java.net.JarURLConnection in project bytecode-viewer by Konloch.
the class ExternalLibrary method load.
/* (non-Javadoc)
* @see the.bytecode.club.bytecodeviewer.loadermodel.ExternalResource#load()
*/
@Override
public JarContents<ClassNode> load() throws IOException {
JarContents<ClassNode> contents = new JarContents<>();
JarURLConnection con = (JarURLConnection) getLocation().openConnection();
JarFile jar = con.getJarFile();
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
try (InputStream is = jar.getInputStream(entry)) {
byte[] bytes = read(is);
if (entry.getName().endsWith(".class")) {
ClassNode cn = create(bytes);
contents.getClassContents().add(cn);
} else {
JarResource resource = new JarResource(entry.getName(), bytes);
contents.getResourceContents().add(resource);
}
}
}
return contents;
}
use of java.net.JarURLConnection in project binnavi by google.
the class JarPluginLoader method getMainClassName.
/**
* Tries to find the main class name out of a JAR package.
*
* @param file The JAR file whose main class is determined.
*
* @return The name of the main class of the JAR file or null.
*
* @throws IOException Thrown if any IO error occurs.
*/
private static String getMainClassName(final File file) throws IOException {
final URL jarUrl = new URL("jar", "", file.toURI().toURL() + "!/");
final JarURLConnection urlConnection = (JarURLConnection) jarUrl.openConnection();
final Attributes attr = urlConnection.getMainAttributes();
return attr == null ? null : attr.getValue(Attributes.Name.MAIN_CLASS);
}
use of java.net.JarURLConnection in project spring-boot by spring-projects.
the class LaunchedURLClassLoaderTests method resolveFromNestedWhileThreadIsInterrupted.
@Test
void resolveFromNestedWhileThreadIsInterrupted() throws Exception {
File file = new File(this.tempDir, "test.jar");
TestJarCreator.createTestJar(file);
try (JarFile jarFile = new JarFile(file)) {
URL url = jarFile.getUrl();
try (LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url }, null)) {
Thread.currentThread().interrupt();
URL resource = loader.getResource("nested.jar!/3.dat");
assertThat(resource.toString()).isEqualTo(url + "nested.jar!/3.dat");
URLConnection connection = resource.openConnection();
try (InputStream input = connection.getInputStream()) {
assertThat(input.read()).isEqualTo(3);
}
((JarURLConnection) connection).getJarFile().close();
} finally {
Thread.interrupted();
}
}
}
Aggregations