URLPermission(String): This method is available in the java.net.URLPermission class of Java.
Syntax:
java.net.URLPermission.URLPermission(String url)
This method takes one argument. This method creates a URLPermission with the given url string and unrestricted methods and requests headers by invoking the two-argument constructor as follows: URLPermission(url, "*:*")
Parameters: Two parameters are required for this method.
url: the url string.
Throws:
1. IllegalArgumentException - if url does not result in a valid URI
Approach 1: When no exception
Java
package com.URLPermission;import java.net.URLPermission;public class URLPermission1 {public static void main(String[] args) {String url = "https://beingcodeexpert.blogspot.com/";URLPermission urlPermission = new URLPermission(url);System.out.println(urlPermission);}}
Output:
("java.net.URLPermission" "https://beingcodeexpert.blogspot.com/" "*:*")
Approach 2: IllegalArgumentException
Java
package com.URLPermission;import java.net.URLPermission;public class URLPermission1 {public static void main(String[] args) {String url = "https:\\beingcodeexpert.blogspot.com/";URLPermission urlPermission = new URLPermission(url);System.out.println(urlPermission);}}
Output:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid URL string: "https:\beingcodeexpert.blogspot.com/" at java.base/java.net.URLPermission.parseURI(URLPermission.java:479) at java.base/java.net.URLPermission.init(URLPermission.java:202) at java.base/java.net.URLPermission.<init>(URLPermission.java:182) at java.base/java.net.URLPermission.<init>(URLPermission.java:239) at com.URLPermission.URLPermission1.main(URLPermission1.java:9)
Some other methods of URLPermission class
URLPermission(String): This method creates a URLPermission with the given url string and unrestricted methods and requests headers by invoking the two-argument constructor as follows: URLPermission(url, "*:*")
URLPermission(String, String): This method creates a new URL permission from a url string and permits the given request methods and user-settable request headers.
equals(Object): his method returns true if, this.getActions().equals(p.getActions())and p's url equals this's url. Returns false otherwise.
getActions(): This method returns the normalized method list and requests a header list, in the form: "method-names: header-names".
hashCode(): This method returns a hashcode calculated from the hashcode of the actions String and the url string.
implies(Permission): This method checks if this URLPermission implies some of the permissions.
No comments:
Post a Comment