sun.net.util.URLUtil Java Examples

The following examples show how to use sun.net.util.URLUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: URLImageSource.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public URLImageSource(URL u) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            java.security.Permission perm =
                  URLUtil.getConnectPermission(u);
            if (perm != null) {
                sm.checkPermission(perm);
            }
        } catch (java.io.IOException ioe) {
            sm.checkConnect(u.getHost(), u.getPort());
        }
    }
    this.url = u;

}
 
Example #2
Source File: SunToolkit.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void checkPermissions(URL url) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            java.security.Permission perm =
                URLUtil.getConnectPermission(url);
            if (perm != null) {
                try {
                    sm.checkPermission(perm);
                } catch (SecurityException se) {
                    // fallback to checkRead/checkConnect for pre 1.2
                    // security managers
                    if ((perm instanceof java.io.FilePermission) &&
                        perm.getActions().indexOf("read") != -1) {
                        sm.checkRead(perm.getName());
                    } else if ((perm instanceof
                        java.net.SocketPermission) &&
                        perm.getActions().indexOf("connect") != -1) {
                        sm.checkConnect(url.getHost(), url.getPort());
                    } else {
                        throw se;
                    }
                }
            }
        } catch (java.io.IOException ioe) {
                sm.checkConnect(url.getHost(), url.getPort());
        }
    }
}
 
Example #3
Source File: JarFileFactory.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Callback method of the URLJarFileCloseController to
 * indicate that the JarFile is close. This way we can
 * remove the JarFile from the cache
 */
public void close(JarFile jarFile) {
    synchronized (instance) {
        URL urlRemoved = urlCache.remove(jarFile);
        if (urlRemoved != null)
            fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
    }
}
 
Example #4
Source File: JarFileFactory.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
JarFile get(URL url, boolean useCaches) throws IOException {

        JarFile result;
        JarFile local_result;

        if (useCaches) {
            synchronized (instance) {
                result = getCachedJarFile(url);
            }
            if (result == null) {
                local_result = URLJarFile.getJarFile(url, this);
                synchronized (instance) {
                    result = getCachedJarFile(url);
                    if (result == null) {
                        fileCache.put(URLUtil.urlNoFragString(url), local_result);
                        urlCache.put(local_result, url);
                        result = local_result;
                    } else {
                        if (local_result != null) {
                            local_result.close();
                        }
                    }
                }
            }
        } else {
            result = URLJarFile.getJarFile(url, this);
        }
        if (result == null)
            throw new FileNotFoundException(url.toString());

        return result;
    }
 
Example #5
Source File: JarFileFactory.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Callback method of the URLJarFileCloseController to
 * indicate that the JarFile is close. This way we can
 * remove the JarFile from the cache
 */
public void close(JarFile jarFile) {
    synchronized (instance) {
        URL urlRemoved = urlCache.remove(jarFile);
        if (urlRemoved != null)
            fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
    }
}
 
Example #6
Source File: URLImageSource.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public URLImageSource(URL u) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            java.security.Permission perm =
                  URLUtil.getConnectPermission(u);
            if (perm != null) {
                try {
                    sm.checkPermission(perm);
                } catch (SecurityException se) {
                    // fallback to checkRead/checkConnect for pre 1.2
                    // security managers
                    if ((perm instanceof java.io.FilePermission) &&
                            perm.getActions().indexOf("read") != -1) {
                        sm.checkRead(perm.getName());
                    } else if ((perm instanceof
                            java.net.SocketPermission) &&
                            perm.getActions().indexOf("connect") != -1) {
                        sm.checkConnect(u.getHost(), u.getPort());
                    } else {
                        throw se;
                    }
                }
            }
        } catch (java.io.IOException ioe) {
                sm.checkConnect(u.getHost(), u.getPort());
        }
    }
    this.url = u;

}
 
Example #7
Source File: URLClassPath.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void validateLookupCache(int index,
                                              String urlNoFragString) {
    if (lookupCacheURLs != null && lookupCacheEnabled) {
        if (index < lookupCacheURLs.length &&
            urlNoFragString.equals(
                URLUtil.urlNoFragString(lookupCacheURLs[index]))) {
            return;
        }
        if (DEBUG || DEBUG_LOOKUP_CACHE) {
            System.out.println("WARNING: resource lookup cache invalidated "
                               + "for lookupCacheLoader at " + index);
        }
        disableAllLookupCaches();
    }
}
 
Example #8
Source File: JarFileFactory.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Callback method of the URLJarFileCloseController to
 * indicate that the JarFile is close. This way we can
 * remove the JarFile from the cache
 */
public void close(JarFile jarFile) {
    synchronized (instance) {
        URL urlRemoved = urlCache.remove(jarFile);
        if (urlRemoved != null)
            fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
    }
}
 
Example #9
Source File: JarFileFactory.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
JarFile get(URL url, boolean useCaches) throws IOException {

        JarFile result;
        JarFile local_result;

        if (useCaches) {
            synchronized (instance) {
                result = getCachedJarFile(url);
            }
            if (result == null) {
                local_result = URLJarFile.getJarFile(url, this);
                synchronized (instance) {
                    result = getCachedJarFile(url);
                    if (result == null) {
                        fileCache.put(URLUtil.urlNoFragString(url), local_result);
                        urlCache.put(local_result, url);
                        result = local_result;
                    } else {
                        if (local_result != null) {
                            local_result.close();
                        }
                    }
                }
            }
        } else {
            result = URLJarFile.getJarFile(url, this);
        }
        if (result == null)
            throw new FileNotFoundException(url.toString());

        return result;
    }
 
Example #10
Source File: JarFileFactory.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Callback method of the URLJarFileCloseController to
 * indicate that the JarFile is close. This way we can
 * remove the JarFile from the cache
 */
public void close(JarFile jarFile) {
    synchronized (instance) {
        URL urlRemoved = urlCache.remove(jarFile);
        if (urlRemoved != null)
            fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
    }
}
 
Example #11
Source File: SunToolkit.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkPermissions(URL url) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            java.security.Permission perm =
                URLUtil.getConnectPermission(url);
            if (perm != null) {
                try {
                    sm.checkPermission(perm);
                } catch (SecurityException se) {
                    // fallback to checkRead/checkConnect for pre 1.2
                    // security managers
                    if ((perm instanceof java.io.FilePermission) &&
                        perm.getActions().indexOf("read") != -1) {
                        sm.checkRead(perm.getName());
                    } else if ((perm instanceof
                        java.net.SocketPermission) &&
                        perm.getActions().indexOf("connect") != -1) {
                        sm.checkConnect(url.getHost(), url.getPort());
                    } else {
                        throw se;
                    }
                }
            }
        } catch (java.io.IOException ioe) {
                sm.checkConnect(url.getHost(), url.getPort());
        }
    }
}
 
Example #12
Source File: URLImageSource.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public URLImageSource(URL u) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            java.security.Permission perm =
                  URLUtil.getConnectPermission(u);
            if (perm != null) {
                try {
                    sm.checkPermission(perm);
                } catch (SecurityException se) {
                    // fallback to checkRead/checkConnect for pre 1.2
                    // security managers
                    if ((perm instanceof java.io.FilePermission) &&
                            perm.getActions().indexOf("read") != -1) {
                        sm.checkRead(perm.getName());
                    } else if ((perm instanceof
                            java.net.SocketPermission) &&
                            perm.getActions().indexOf("connect") != -1) {
                        sm.checkConnect(u.getHost(), u.getPort());
                    } else {
                        throw se;
                    }
                }
            }
        } catch (java.io.IOException ioe) {
                sm.checkConnect(u.getHost(), u.getPort());
        }
    }
    this.url = u;

}
 
Example #13
Source File: URLClassPath.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void validateLookupCache(int index,
                                              String urlNoFragString) {
    if (lookupCacheURLs != null && lookupCacheEnabled) {
        if (index < lookupCacheURLs.length &&
            urlNoFragString.equals(
                URLUtil.urlNoFragString(lookupCacheURLs[index]))) {
            return;
        }
        if (DEBUG || DEBUG_LOOKUP_CACHE) {
            System.out.println("WARNING: resource lookup cache invalidated "
                               + "for lookupCacheLoader at " + index);
        }
        disableAllLookupCaches();
    }
}
 
Example #14
Source File: SunToolkit.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkPermissions(URL url) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            java.security.Permission perm =
                URLUtil.getConnectPermission(url);
            if (perm != null) {
                try {
                    sm.checkPermission(perm);
                } catch (SecurityException se) {
                    // fallback to checkRead/checkConnect for pre 1.2
                    // security managers
                    if ((perm instanceof java.io.FilePermission) &&
                        perm.getActions().indexOf("read") != -1) {
                        sm.checkRead(perm.getName());
                    } else if ((perm instanceof
                        java.net.SocketPermission) &&
                        perm.getActions().indexOf("connect") != -1) {
                        sm.checkConnect(url.getHost(), url.getPort());
                    } else {
                        throw se;
                    }
                }
            }
        } catch (java.io.IOException ioe) {
                sm.checkConnect(url.getHost(), url.getPort());
        }
    }
}
 
Example #15
Source File: URLClassPath.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void validateLookupCache(int index,
                                              String urlNoFragString) {
    if (lookupCacheURLs != null && lookupCacheEnabled) {
        if (index < lookupCacheURLs.length &&
            urlNoFragString.equals(
                URLUtil.urlNoFragString(lookupCacheURLs[index]))) {
            return;
        }
        if (DEBUG || DEBUG_LOOKUP_CACHE) {
            System.out.println("WARNING: resource lookup cache invalidated "
                               + "for lookupCacheLoader at " + index);
        }
        disableAllLookupCaches();
    }
}
 
Example #16
Source File: URLImageSource.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public URLImageSource(URL u) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            java.security.Permission perm =
                  URLUtil.getConnectPermission(u);
            if (perm != null) {
                try {
                    sm.checkPermission(perm);
                } catch (SecurityException se) {
                    // fallback to checkRead/checkConnect for pre 1.2
                    // security managers
                    if ((perm instanceof java.io.FilePermission) &&
                            perm.getActions().indexOf("read") != -1) {
                        sm.checkRead(perm.getName());
                    } else if ((perm instanceof
                            java.net.SocketPermission) &&
                            perm.getActions().indexOf("connect") != -1) {
                        sm.checkConnect(u.getHost(), u.getPort());
                    } else {
                        throw se;
                    }
                }
            }
        } catch (java.io.IOException ioe) {
                sm.checkConnect(u.getHost(), u.getPort());
        }
    }
    this.url = u;

}
 
Example #17
Source File: JarFileFactory.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Callback method of the URLJarFileCloseController to
 * indicate that the JarFile is close. This way we can
 * remove the JarFile from the cache
 */
public void close(JarFile jarFile) {
    synchronized (instance) {
        URL urlRemoved = urlCache.remove(jarFile);
        if (urlRemoved != null)
            fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
    }
}
 
Example #18
Source File: JarFileFactory.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Callback method of the URLJarFileCloseController to
 * indicate that the JarFile is close. This way we can
 * remove the JarFile from the cache
 */
public void close(JarFile jarFile) {
    synchronized (instance) {
        URL urlRemoved = urlCache.remove(jarFile);
        if (urlRemoved != null)
            fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
    }
}
 
Example #19
Source File: JarFileFactory.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
JarFile get(URL url, boolean useCaches) throws IOException {

        JarFile result;
        JarFile local_result;

        if (useCaches) {
            synchronized (instance) {
                result = getCachedJarFile(url);
            }
            if (result == null) {
                local_result = URLJarFile.getJarFile(url, this);
                synchronized (instance) {
                    result = getCachedJarFile(url);
                    if (result == null) {
                        fileCache.put(URLUtil.urlNoFragString(url), local_result);
                        urlCache.put(local_result, url);
                        result = local_result;
                    } else {
                        if (local_result != null) {
                            local_result.close();
                        }
                    }
                }
            }
        } else {
            result = URLJarFile.getJarFile(url, this);
        }
        if (result == null)
            throw new FileNotFoundException(url.toString());

        return result;
    }
 
Example #20
Source File: JarFileFactory.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Callback method of the URLJarFileCloseController to
 * indicate that the JarFile is close. This way we can
 * remove the JarFile from the cache
 */
public void close(JarFile jarFile) {
    synchronized (instance) {
        URL urlRemoved = urlCache.remove(jarFile);
        if (urlRemoved != null)
            fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
    }
}
 
Example #21
Source File: URLClassPath.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void validateLookupCache(int index,
                                              String urlNoFragString) {
    if (lookupCacheURLs != null && lookupCacheEnabled) {
        if (index < lookupCacheURLs.length &&
            urlNoFragString.equals(
                URLUtil.urlNoFragString(lookupCacheURLs[index]))) {
            return;
        }
        if (DEBUG || DEBUG_LOOKUP_CACHE) {
            System.out.println("WARNING: resource lookup cache invalidated "
                               + "for lookupCacheLoader at " + index);
        }
        disableAllLookupCaches();
    }
}
 
Example #22
Source File: URLImageSource.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public URLImageSource(URL u) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            java.security.Permission perm =
                  URLUtil.getConnectPermission(u);
            if (perm != null) {
                try {
                    sm.checkPermission(perm);
                } catch (SecurityException se) {
                    // fallback to checkRead/checkConnect for pre 1.2
                    // security managers
                    if ((perm instanceof java.io.FilePermission) &&
                            perm.getActions().indexOf("read") != -1) {
                        sm.checkRead(perm.getName());
                    } else if ((perm instanceof
                            java.net.SocketPermission) &&
                            perm.getActions().indexOf("connect") != -1) {
                        sm.checkConnect(u.getHost(), u.getPort());
                    } else {
                        throw se;
                    }
                }
            }
        } catch (java.io.IOException ioe) {
                sm.checkConnect(u.getHost(), u.getPort());
        }
    }
    this.url = u;

}
 
Example #23
Source File: SunToolkit.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkPermissions(URL url) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            java.security.Permission perm =
                URLUtil.getConnectPermission(url);
            if (perm != null) {
                try {
                    sm.checkPermission(perm);
                } catch (SecurityException se) {
                    // fallback to checkRead/checkConnect for pre 1.2
                    // security managers
                    if ((perm instanceof java.io.FilePermission) &&
                        perm.getActions().indexOf("read") != -1) {
                        sm.checkRead(perm.getName());
                    } else if ((perm instanceof
                        java.net.SocketPermission) &&
                        perm.getActions().indexOf("connect") != -1) {
                        sm.checkConnect(url.getHost(), url.getPort());
                    } else {
                        throw se;
                    }
                }
            }
        } catch (java.io.IOException ioe) {
                sm.checkConnect(url.getHost(), url.getPort());
        }
    }
}
 
Example #24
Source File: URLImageSource.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public URLImageSource(URL u) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            java.security.Permission perm =
                  URLUtil.getConnectPermission(u);
            if (perm != null) {
                try {
                    sm.checkPermission(perm);
                } catch (SecurityException se) {
                    // fallback to checkRead/checkConnect for pre 1.2
                    // security managers
                    if ((perm instanceof java.io.FilePermission) &&
                            perm.getActions().indexOf("read") != -1) {
                        sm.checkRead(perm.getName());
                    } else if ((perm instanceof
                            java.net.SocketPermission) &&
                            perm.getActions().indexOf("connect") != -1) {
                        sm.checkConnect(u.getHost(), u.getPort());
                    } else {
                        throw se;
                    }
                }
            }
        } catch (java.io.IOException ioe) {
                sm.checkConnect(u.getHost(), u.getPort());
        }
    }
    this.url = u;

}
 
Example #25
Source File: SunToolkit.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkPermissions(URL url) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            java.security.Permission perm =
                URLUtil.getConnectPermission(url);
            if (perm != null) {
                try {
                    sm.checkPermission(perm);
                } catch (SecurityException se) {
                    // fallback to checkRead/checkConnect for pre 1.2
                    // security managers
                    if ((perm instanceof java.io.FilePermission) &&
                        perm.getActions().indexOf("read") != -1) {
                        sm.checkRead(perm.getName());
                    } else if ((perm instanceof
                        java.net.SocketPermission) &&
                        perm.getActions().indexOf("connect") != -1) {
                        sm.checkConnect(url.getHost(), url.getPort());
                    } else {
                        throw se;
                    }
                }
            }
        } catch (java.io.IOException ioe) {
                sm.checkConnect(url.getHost(), url.getPort());
        }
    }
}
 
Example #26
Source File: CodeSource.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a CodeSource and associates it with the specified
 * location and set of code signers.
 *
 * @param url the location (URL).  It may be {@code null}.
 * @param signers the code signers. It may be {@code null}. The contents
 * of the array are copied to protect against subsequent modification.
 *
 * @since 1.5
 */
public CodeSource(URL url, CodeSigner[] signers) {
    this.location = url;
    if (url != null) {
        this.locationNoFragString = URLUtil.urlNoFragString(url);
    }

    // Copy the supplied signers
    if (signers != null) {
        this.signers = signers.clone();
    }
}
 
Example #27
Source File: CodeSource.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a CodeSource and associates it with the specified
 * location and set of certificates.
 *
 * @param url the location (URL).  It may be {@code null}.
 * @param certs the certificate(s). It may be {@code null}. The contents
 * of the array are copied to protect against subsequent modification.
 */
public CodeSource(URL url, java.security.cert.Certificate[] certs) {
    this.location = url;
    if (url != null) {
        this.locationNoFragString = URLUtil.urlNoFragString(url);
    }

    // Copy the supplied certs
    if (certs != null) {
        this.certs = certs.clone();
    }
}
 
Example #28
Source File: SunToolkit.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private static void checkPermissions(URL url) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            java.security.Permission perm =
                URLUtil.getConnectPermission(url);
            if (perm != null) {
                sm.checkPermission(perm);
            }
        } catch (java.io.IOException ioe) {
            sm.checkConnect(url.getHost(), url.getPort());
        }
    }
}
 
Example #29
Source File: JarFileFactory.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Callback method of the URLJarFileCloseController to
 * indicate that the JarFile is close. This way we can
 * remove the JarFile from the cache
 */
public void close(JarFile jarFile) {
    synchronized (instance) {
        URL urlRemoved = urlCache.remove(jarFile);
        if (urlRemoved != null)
            fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
    }
}
 
Example #30
Source File: CodeSource.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a CodeSource and associates it with the specified
 * location and set of certificates.
 *
 * @param url the location (URL).  It may be {@code null}.
 * @param certs the certificate(s). It may be {@code null}. The contents
 * of the array are copied to protect against subsequent modification.
 */
public CodeSource(URL url, java.security.cert.Certificate[] certs) {
    this.location = url;
    if (url != null) {
        this.locationNoFragString = URLUtil.urlNoFragString(url);
    }

    // Copy the supplied certs
    if (certs != null) {
        this.certs = certs.clone();
    }
}