use of java.net.JarURLConnection in project wicket by apache.
the class Connections method getLastModified.
/**
* Gets last modified date of the given {@link URL}
*
* @param url
* @return last modified timestamp or <code>null</code> if not available
* @throws IOException
*/
public static Time getLastModified(final URL url) throws IOException {
// check if url points to a local file
final File file = Files.getLocalFileFromUrl(url);
if (file != null) {
// in that case we can get the timestamp faster
return Files.getLastModified(file);
}
// otherwise open the url and proceed
URLConnection connection = url.openConnection();
final long milliseconds;
try {
if (connection instanceof JarURLConnection) {
JarURLConnection jarUrlConnection = (JarURLConnection) connection;
URL jarFileUrl = jarUrlConnection.getJarFileURL();
URLConnection jarFileConnection = jarFileUrl.openConnection();
jarFileConnection.setDoInput(false);
// get timestamp from JAR
milliseconds = jarFileConnection.getLastModified();
} else {
// get timestamp from URL
milliseconds = connection.getLastModified();
}
// return null if timestamp is unavailable
if (milliseconds == 0) {
return null;
}
// return UNIX timestamp
return Time.millis(milliseconds);
} finally {
closeQuietly(connection);
}
}
use of java.net.JarURLConnection in project android_packages_apps_Settings by crdroidandroid.
the class ClassScanner method getClassesForPackage.
public List<Class<?>> getClassesForPackage(String packageName) throws ClassNotFoundException {
final List<Class<?>> classes = new ArrayList<>();
try {
final Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(packageName.replace('.', '/'));
if (!resources.hasMoreElements()) {
return classes;
}
URL url = resources.nextElement();
while (url != null) {
final URLConnection connection = url.openConnection();
if (connection instanceof JarURLConnection) {
loadClassFromJar((JarURLConnection) connection, packageName, classes);
} else {
loadClassFromDirectory(new File(URLDecoder.decode(url.getPath(), "UTF-8")), packageName, classes);
}
if (resources.hasMoreElements()) {
url = resources.nextElement();
} else {
break;
}
}
} catch (final IOException e) {
throw new ClassNotFoundException("Error when parsing " + packageName, e);
}
return classes;
}
use of java.net.JarURLConnection in project android_packages_apps_Settings by SudaMod.
the class ClassScanner method getClassesForPackage.
public List<Class<?>> getClassesForPackage(String packageName) throws ClassNotFoundException {
final List<Class<?>> classes = new ArrayList<>();
try {
final Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(packageName.replace('.', '/'));
if (!resources.hasMoreElements()) {
return classes;
}
URL url = resources.nextElement();
while (url != null) {
final URLConnection connection = url.openConnection();
if (connection instanceof JarURLConnection) {
loadClassFromJar((JarURLConnection) connection, packageName, classes);
} else {
loadClassFromDirectory(new File(URLDecoder.decode(url.getPath(), "UTF-8")), packageName, classes);
}
if (resources.hasMoreElements()) {
url = resources.nextElement();
} else {
break;
}
}
} catch (final IOException e) {
throw new ClassNotFoundException("Error when parsing " + packageName, e);
}
return classes;
}
use of java.net.JarURLConnection in project incubator-rya by apache.
the class RyaBannerProvider method loadVersion.
/**
* Loads the version number from the Rya Shell's MANIFEST.MF file.
*
* @return The version number of the Rya Shell.
*/
private String loadVersion() {
final String className = getClass().getSimpleName() + ".class";
final String classPath = getClass().getResource(className).toString();
try {
final URL classUrl = new URL(classPath);
final JarURLConnection jarConnection = (JarURLConnection) classUrl.openConnection();
final Manifest manifest = jarConnection.getManifest();
final Attributes attributes = manifest.getMainAttributes();
return attributes.getValue("Implementation-Version");
} catch (final IOException e) {
log.error("Could not load the application's version from it's manifest.", e);
}
return "UNKNOWN";
}
use of java.net.JarURLConnection in project minijax by minijax.
the class ClassPathScanner method checkJarFile.
private void checkJarFile(final ClassLoader classLoader, final URL url, final String pckgname) throws IOException {
final JarURLConnection conn = (JarURLConnection) url.openConnection();
final JarFile jarFile = conn.getJarFile();
final Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
final JarEntry jarEntry = entries.nextElement();
String name = jarEntry.getName();
if (name.endsWith(".class")) {
name = name.substring(0, name.length() - 6).replace('/', '.');
if (name.startsWith(pckgname)) {
addClass(classLoader, name);
}
}
}
}
Aggregations