当前位置: 首页>>代码示例>>Java>>正文


Java URLConnection.getPermission方法代码示例

本文整理汇总了Java中java.net.URLConnection.getPermission方法的典型用法代码示例。如果您正苦于以下问题:Java URLConnection.getPermission方法的具体用法?Java URLConnection.getPermission怎么用?Java URLConnection.getPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.URLConnection的用法示例。


在下文中一共展示了URLConnection.getPermission方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: check

import java.net.URLConnection; //导入方法依赖的package包/类
static void check(URL url) throws IOException {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        URLConnection urlConnection = url.openConnection();
        Permission perm = urlConnection.getPermission();
        if (perm != null) {
            try {
                security.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) {
                    security.checkRead(perm.getName());
                } else if ((perm instanceof
                    java.net.SocketPermission) &&
                    perm.getActions().indexOf("connect") != -1) {
                    URL locUrl = url;
                    if (urlConnection instanceof JarURLConnection) {
                        locUrl = ((JarURLConnection)urlConnection).getJarFileURL();
                    }
                    security.checkConnect(locUrl.getHost(),
                                          locUrl.getPort());
                } else {
                    throw se;
                }
            }
        }
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:31,代码来源:URLClassPath.java

示例2: getPermission

import java.net.URLConnection; //导入方法依赖的package包/类
private Permission getPermission(JarFile jarFile) {
    try {
        URLConnection uc = getConnection(jarFile);
        if (uc != null)
            return uc.getPermission();
    } catch (IOException ioe) {
        // gulp
    }

    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:JarFileFactory.java

示例3: check

import java.net.URLConnection; //导入方法依赖的package包/类
public static void check(URL url) throws IOException {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        URLConnection urlConnection = url.openConnection();
        Permission perm = urlConnection.getPermission();
        if (perm != null) {
            try {
                security.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) {
                    security.checkRead(perm.getName());
                } else if ((perm instanceof
                    java.net.SocketPermission) &&
                    perm.getActions().indexOf("connect") != -1) {
                    URL locUrl = url;
                    if (urlConnection instanceof JarURLConnection) {
                        locUrl = ((JarURLConnection)urlConnection).getJarFileURL();
                    }
                    security.checkConnect(locUrl.getHost(),
                                          locUrl.getPort());
                } else {
                    throw se;
                }
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:URLClassPath.java


注:本文中的java.net.URLConnection.getPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。