SecurityManager类的checkListen()方法 (SecurityManager Class checkListen() method)

  • checkListen() method is available in java.lang package.

    checkListen()方法在java.lang包中可用。

  • checkListen() method invokes checkPermission with the given SocketPermission("localhost:"+port_no,"listen") when the given argument value is not equal to 0 otherwise it invokes checkPermission with the SocketPermission("localhost:1024-","listen") when the given argument value equal to 0.

    当给定参数值不等于0时, checkListen()方法使用给定的SocketPermission(“ localhost:” + port_no,“ listen”)调用checkPermission;否则,使用SocketPermission(“ localhost:1024-”,“ listen”)调用checkPermission ),则给定参数值等于0。

  • checkListen() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    checkListen()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • checkListen() method may throw an exception at the time of establishing the connection.

    建立连接时, checkListen()方法可能会引发异常。

    SecurityException – This exception may throw when the calling thread is not allowed to listen (i.e. it does not wait for a connection request) on the given port.

    SecurityException-如果不允许调用线程在给定端口上侦听(即,它不等待连接请求),则可能引发此异常。

Syntax:

句法:

    public void checkListen(int port_no);

Parameter(s):

参数:

  • int port_no – represents the local port number.

    int port_no –表示本地端口号。

Return value:

返回值:

The return type of this method is void, it returns nothing.

此方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example
// of void checkListen(int port_no)
// method of SecurityManager
public class CheckListen extends SecurityManager {// override checkListen() of SecurityManager
public void checkListen(int port_no) {throw new SecurityException("No such port exists!!!!");
}
public static void main(String[] args) {int port_no = 8090;
// By using setProperty() method is to set the policy property
// with security manager
System.setProperty("java.security.policy", "file:/C:/java.policy");
// Instantiating a CheckListen object
CheckListen cl = new CheckListen();
// By using setSecurityManager() method is to set the
// security manager
System.setSecurityManager(cl);
// By using checkListen(8090) method is to check
// port number
cl.checkListen(8090);
// Display the message
System.out.println("Not Restricted..");
}
}

Output

输出量

Exception in thread "main" java.lang.SecurityException: No such port exists!!!!at CheckListen.checkListen(CheckListen.java:8)at CheckListen.main(CheckListen.java:27)

翻译自: https://www.includehelp.com/java/securitymanager-checklisten-method-with-example.aspx

Java SecurityManager checkListen()方法与示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  3. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  4. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  5. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  6. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  7. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

  8. java arraylist.add(),Java ArrayList add()方法与示例

    ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...

  9. java rollback用法,Java Connection rollBack()方法与示例

    回滚操作将撤消当前事务所做的所有更改,即,如果调用Connection接口的rollBack()方法,则所有修改都将还原到最后一次提交. 您还可以通过将所需的Savepoint对象作为参数传递给此方法 ...

最新文章

  1. python编程入门与案例详解课后题答案-Python入门之三角函数sin()函数实例详解
  2. 机器学习笔记:Adagrad
  3. python英文高频句统计_使用Python 统计高频字数的方法
  4. 工具-eclipse-hibernate关于快速生成*.hbm.xml文件,与bean文件的操作,不使用hibernate tool解决办法之一,主要为了快速开发,写的小工具
  5. 演练 制作百度音乐标签页面 0929
  6. Java中udp/tcp的发送和接收
  7. 计算机语言语法语义,程序设计语言语义
  8. android谷歌打印插件下载地址,谷歌浏览器打印插件(Print Plus)
  9. JavaWeb - 国家语言代码表
  10. snmp中mib文件解析
  11. 租房系统源码(仅供参考)
  12. pytorch中transform的使用
  13. 简报 | QuarkChain北京站见面会即将召开;HiCTO创始人/前百姓网CTO潘晓良加入CarBlock;LinkEye上线FCoin受关注;Coinbase推出托管服务
  14. 解决PDapp占据C盘空间的方法
  15. List集合遍历for循环优化
  16. 扦插技术图解_桂花的扦插方法(图解)
  17. 喜欢最新电子产品的人
  18. Spring Security应用详解(集成SpringBoot)
  19. 电脑重装系统后桌面没有计算机图标,电脑重装系统后桌面没有图标了怎么办
  20. Linux-监控命令

热门文章

  1. sql双表查询java代码_原生sql 多表查询
  2. 参考文献中会议名称怎么缩写_期刊缩写查询总结
  3. 关于模板引擎handlebars.js基本用法
  4. css实现div内一段文本的两端对齐
  5. Table Dragger - 简单的 JS 拖放排序表格插件
  6. CSS基本知识(慕课网)
  7. scrapy架构解析
  8. Java访问权限的范围
  9. selenium 等待页面加载完成
  10. Axis通过wsdd部署Web Service