FilePermission implies(Permission) in Java

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;

            @Override
            public boolean implies(Permission permission) {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public int hashCode() {
                // TODO Auto-generated method stub
                return 0;
            }

            @Override
            public String getActions() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public boolean equals(Object obj) {
                // TODO Auto-generated method stub
                return 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