implies(Permission): This method is available in the java.io.FilePermission class of Java.
Syntax:
boolean java.io.FilePermission.implies(Permission p)
This method takes one argument. This method checks if this FilePermission object "implies" the specified permission.
More specifically, this method returns true if:
1. p is an instance of FilePermission.
2. p's actions are a proper subset of this object's actions.
3. p's pathname is implied by this object pathname.
Parameters: One parameter is required for this method.
p: the permission to check against.
Returns: true if the specified permission is not null and is implied by this object, false otherwise.
Exceptions: NA
Approach
Java
import java.io.FilePermission;import java.security.Permission;public class FilePermissionimplies {public static void main(String[] args) {String path = "D:\\hello.txt";String actions = "read";FilePermission filePermission =new FilePermission(path, actions);Permission p = new Permission("read") {/****/private static final long serialVersionUID = 1L;@Overridepublic boolean implies(Permission permission) {// TODO Auto-generated method stubreturn false;}@Overridepublic int hashCode() {// TODO Auto-generated method stubreturn 0;}@Overridepublic String getActions() {// TODO Auto-generated method stubreturn null;}@Overridepublic boolean equals(Object obj) {// TODO Auto-generated method stubreturn false;}};System.out.println(filePermission.implies(p));}}
Output:
false
Some other methods of FilePermission
equals(Object): This method checks two FilePermission objects for equality. Checks that obj is a FilePermission, and has the same pathname and actions as this object.
FilePermission(String, String): This method creates a new FilePermission object with the specified actions.
getActions(): This method returns the "canonical string representation" of the actions.
hashCode(): This method returns the hash code value for this object.
implies(Permission): This method checks if this FilePermission object "implies" the specified permission.
newPermissionCollection(): This method returns a new PermissionCollection object for storing FilePermission objects.
No comments:
Post a Comment