Java Utililty Methods URL Load

List of utility methods to do URL Load

Description

The list of methods to do URL Load are organized into topic(s).

Method

voidfindResourcesFromJar(Collection urls, URL url, String resource, ClassLoader cl)
Find all resources from a given jar file and add them to the provided list.
try {
    final JarURLConnection conn = (JarURLConnection) url.openConnection();
    final URL jurl = conn.getJarFileURL();
    try (final JarInputStream jar = new JarInputStream(jurl.openStream());) {
        while (true) {
            final JarEntry entry = jar.getNextJarEntry();
            if (entry == null) {
                break;
...
ResourceBundlegetBundle(String basename, Locale locale, ClassLoader cl, URL url)
Get a resource bundle via the network class loader given the resource name and the locale.
ResourceBundle resourceBundle = null;
String resource = basename.replace('.', '/') + ".properties";
System.out.println("Looking for '" + resource + "' in locale " + locale + " (display name = "
        + locale.getDisplayName() + "'");
if (locale != null && !"en".equalsIgnoreCase(locale.toString())
        && !"en_GB".equalsIgnoreCase(locale.toString())) {
    try {
        URL resourceUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(),
...
StringgetManifestAsString(URLClassLoader cl, String jarBaseName)
get Manifest As String
try {
    Enumeration<URL> e = ((URLClassLoader) cl).findResources("META-INF/MANIFEST.MF");
    while (e.hasMoreElements()) {
        URL url = e.nextElement();
        String urlString = url.toString();
        if (urlString.indexOf(jarBaseName) > 0) {
            StringBuilder sb = new StringBuilder();
            int c;
...
Propertiesload(Iterable urls)
load
Properties properties = new Properties();
for (URL url : urls) {
    properties.load(url.openStream());
return properties;
Stringload(String fileOrURL)
Load entire contents of a file or URL into a string.
try {
    URL url = new URL(fileOrURL);
    return new String(loadURL(url));
} catch (Exception e) {
    return loadFile(fileOrURL);
Listload(URL pUrl)
load
final InputStream is = pUrl.openStream();
final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
final List<String> lines = new ArrayList<String>();
try {
    String line = null;
    while ((line = reader.readLine()) != null) {
        lines.add(line);
    return lines;
} finally {
    reader.close();
Propertiesload(URL url)
load
Properties props = new Properties();
try {
    InputStream is = null;
    try {
        is = url.openStream();
        props.load(is);
    } finally {
        if (is != null)
...
StringBufferload(URL url)
load
try {
    StringBuffer sb = new StringBuffer();
        byte[] buf = new byte[1024];
        int n;
        InputStream is = url.openStream();
        while (-1 != (n = is.read(buf))) {
            sb.append(new String(buf));
...
byte[]load(URL url, boolean allowCache)
Loads and returns data from the specified URL.
InputStream in = inputStreamForURL(url, allowCache);
try {
    return readToEnd(in);
} finally {
    try {
        in.close();
    } catch (IOException e) {
byte[]loadByteArray(URL url)
Load a byte [] from a URL.
InputStream iStream = new BufferedInputStream(url.openStream());
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
byte[] blk = new byte[8192];
int bytesRead;
while ((bytesRead = iStream.read(blk)) != -1) {
    oStream.write(blk, 0, bytesRead);
iStream.close();
...