net.sf.mmm.util.file.base
Class FileAccessPermissions

java.lang.Object
  extended by net.sf.mmm.util.file.base.FileAccessPermissions
All Implemented Interfaces:
Cloneable

public class FileAccessPermissions
extends Object
implements Cloneable

This class represents the permissions of a file.

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private static int MASK_ALL
           
private static int MASK_ALL_EXECUTABLE
           
private static int MASK_ALL_READABLE
           
private static int MASK_ALL_WRITABLE
           
static int MASK_EXECUTABLE
           
private static int MASK_FULL_DIRECTORY_ACCESS
           
private static int MASK_FULL_FILE_ACCESS
           
private static int MASK_GROUP
           
private static int MASK_GROUP_FLAGS
           
private static int MASK_MAX
           
private static int MASK_OTHERS
           
private static int MASK_OTHERS_FLAGS
           
static int MASK_READABLE
           
static int MASK_SETGID
           
static int MASK_SETUID
           
static int MASK_STICKY
           
private static int MASK_USER
           
private static int MASK_USER_FLAGS
           
static int MASK_WRITABLE
           
private  int maskBits
           
 
Constructor Summary
FileAccessPermissions()
          The constructor.
FileAccessPermissions(int mask)
          The constructor.
 
Method Summary
 void chmod(String chmod)
          This method allows to change the modifiers by a string expression.
 FileAccessPermissions clone()
          
static FileAccessPermissions createByUmask(int umask, boolean isDirectory)
          This method create a new FileAccessPermissions instance according to the given umask (user file creation mode mask).
 boolean equals(Object obj)
          
 int getMaskBits()
          This method gets the FileAccessPermissions encoded as a single integer value.
private  boolean hasBits(int bitMask)
          This method determines if the flags given by bitMask are set in this mask.
private  boolean hasFlag(FileAccessClass fileModeClass, int bitMask)
          This method determines if the flag(s) given by bitMask is set in this mask for the given fileModeClass.
 int hashCode()
          
 boolean isExecutable(FileAccessClass fileModeClass)
          This method determines if this mask is executable for the given fileModeClass.
 boolean isReadable(FileAccessClass fileModeClass)
          This method determines if this mask is readable for the given fileModeClass.
 boolean isSetgid()
          This method determines the value of the setgid flag ("set group ID").
 boolean isSetuid()
          This method determines the value of the setuid flag ("set user ID").
 boolean isSticky()
          This method determines the value of the sticky flag.
 boolean isWritable(FileAccessClass fileModeClass)
          This method determines if this mask is writable for the given fileModeClass.
private static int parseOctalMode(CharSequenceScanner parse)
          This method parses the current state of the chmod argument given by parse in octal mode.
private static int parseSymbolicMode(CharSequenceScanner parse, int maskBits)
          This method parses a symbolic-mode segment from parse.
private static int parseUGO(CharSequenceScanner parse)
          This method parses the ugoa prefix indicating which flags to modify.
private  void setBits(int bitMask, boolean set)
          This method sets or unsets the flags given by bitMask in this mask according to the given flag.
 void setExecutable(boolean executable)
          This method sets the executable flag of this this mask for ALL access-classes to the given value (executable).
 void setExecutable(FileAccessClass fileModeClass, boolean executable)
          This method sets the executable flag of this this mask for the given fileModeClass to the given value (executable).
private  void setFlag(FileAccessClass fileModeClass, int bitMask, boolean flag)
          This method sets the flag(s) given by bitMask of this this mask for the given fileModeClass to the given value (flag).
 void setMaskBits(int mask)
          This method sets the bitwise encoded mask.
 void setReadable(boolean readable)
          This method sets the readable flag of this this mask for ALL access-classes to the given value (readable).
 void setReadable(FileAccessClass fileModeClass, boolean readable)
          This method sets the readable flag of this this mask for the given fileModeClass to the given value (readable).
 void setSetgid(boolean setgid)
          This method sets the setuid flag to the given value setuid.
 void setSetuid(boolean setuid)
          This method sets the setuid flag to the given value setuid.
 void setSticky(boolean sticky)
          This method sets the sticky flag to the given value sticky.
 void setWritable(boolean writable)
          This method sets the writable flag of this this mask for ALL access-classes to the given value (writable).
 void setWritable(FileAccessClass fileModeClass, boolean writable)
          This method sets the writable flag of this this mask for the given fileModeClass to the given value (writable).
private  int shiftMask(FileAccessClass fileModeClass, int bitMask)
          This method shifts the given bitMask according to the given fileModeClass.
 String toString()
          
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MASK_MAX

private static final int MASK_MAX
See Also:
parseUGO(CharSequenceScanner), Constant Field Values

MASK_USER

private static final int MASK_USER
See Also:
parseUGO(CharSequenceScanner), Constant Field Values

MASK_GROUP

private static final int MASK_GROUP
See Also:
parseUGO(CharSequenceScanner), Constant Field Values

MASK_OTHERS

private static final int MASK_OTHERS
See Also:
parseUGO(CharSequenceScanner), Constant Field Values

MASK_ALL

private static final int MASK_ALL
See Also:
parseUGO(CharSequenceScanner), Constant Field Values

MASK_READABLE

public static final int MASK_READABLE
See Also:
isReadable(FileAccessClass), Constant Field Values

MASK_WRITABLE

public static final int MASK_WRITABLE
See Also:
isWritable(FileAccessClass), Constant Field Values

MASK_EXECUTABLE

public static final int MASK_EXECUTABLE
See Also:
isExecutable(FileAccessClass), Constant Field Values

MASK_SETUID

public static final int MASK_SETUID
See Also:
isSetuid(), Constant Field Values

MASK_SETGID

public static final int MASK_SETGID
See Also:
isSetgid(), Constant Field Values

MASK_STICKY

public static final int MASK_STICKY
See Also:
isSticky(), Constant Field Values

MASK_USER_FLAGS

private static final int MASK_USER_FLAGS
See Also:
chmod(String), Constant Field Values

MASK_GROUP_FLAGS

private static final int MASK_GROUP_FLAGS
See Also:
chmod(String), Constant Field Values

MASK_OTHERS_FLAGS

private static final int MASK_OTHERS_FLAGS
See Also:
chmod(String), Constant Field Values

MASK_FULL_FILE_ACCESS

private static final int MASK_FULL_FILE_ACCESS
See Also:
createByUmask(int, boolean), Constant Field Values

MASK_FULL_DIRECTORY_ACCESS

private static final int MASK_FULL_DIRECTORY_ACCESS
See Also:
createByUmask(int, boolean), Constant Field Values

MASK_ALL_EXECUTABLE

private static final int MASK_ALL_EXECUTABLE
See Also:
setExecutable(boolean), Constant Field Values

MASK_ALL_WRITABLE

private static final int MASK_ALL_WRITABLE
See Also:
setWritable(boolean), Constant Field Values

MASK_ALL_READABLE

private static final int MASK_ALL_READABLE
See Also:
setReadable(boolean), Constant Field Values

maskBits

private int maskBits
See Also:
getMaskBits()
Constructor Detail

FileAccessPermissions

public FileAccessPermissions()
The constructor.


FileAccessPermissions

public FileAccessPermissions(int mask)
The constructor.

Parameters:
mask - is the mask.
Method Detail

createByUmask

public static FileAccessPermissions createByUmask(int umask,
                                                  boolean isDirectory)
This method create a new FileAccessPermissions instance according to the given umask (user file creation mode mask).

Parameters:
umask - is the umask.
isDirectory - true if the the FileAccessPermissions is to be created for a directory, false for a regular file.
Returns:
the according FileAccessPermissions.

getMaskBits

public int getMaskBits()
This method gets the FileAccessPermissions encoded as a single integer value. The value is in the same format as the octal notation for the command chmod. Only the last 12 bits of the mask can be set.

Returns:
the encoded mask.

setMaskBits

public void setMaskBits(int mask)
                 throws IllegalArgumentException
This method sets the bitwise encoded mask.

Parameters:
mask - the mask to set.
Throws:
IllegalArgumentException - if the given mask is negative or greater than 07777 (== 0xFFF == 4095).

isReadable

public boolean isReadable(FileAccessClass fileModeClass)
This method determines if this mask is readable for the given fileModeClass.

Parameters:
fileModeClass - is the class of access ( FileAccessClass.USER, FileAccessClass.GROUP, or FileAccessClass.OTHERS).
Returns:
true if the mask is readable for the given fileModeClass, false otherwise.

setReadable

public void setReadable(boolean readable)
This method sets the readable flag of this this mask for ALL access-classes to the given value (readable).

Parameters:
readable - if true the mask will be readable, if false it will NOT be readable.

setReadable

public void setReadable(FileAccessClass fileModeClass,
                        boolean readable)
This method sets the readable flag of this this mask for the given fileModeClass to the given value (readable).

Parameters:
fileModeClass - is the class of access ( FileAccessClass.USER, FileAccessClass.GROUP, or FileAccessClass.OTHERS).
readable - if true the mask will be readable for the given fileModeClass, if false it will NOT be readable.

isWritable

public boolean isWritable(FileAccessClass fileModeClass)
This method determines if this mask is writable for the given fileModeClass.

Parameters:
fileModeClass - is the class of access ( FileAccessClass.USER, FileAccessClass.GROUP, or FileAccessClass.OTHERS).
Returns:
true if the mask is writable for the given fileModeClass, false otherwise.

setWritable

public void setWritable(boolean writable)
This method sets the writable flag of this this mask for ALL access-classes to the given value (writable).

Parameters:
writable - if true the mask will be writable, if false it will NOT be writable.

setWritable

public void setWritable(FileAccessClass fileModeClass,
                        boolean writable)
This method sets the writable flag of this this mask for the given fileModeClass to the given value (writable).

Parameters:
fileModeClass - is the class of access ( FileAccessClass.USER, FileAccessClass.GROUP, or FileAccessClass.OTHERS).
writable - if true the mask will be writable for the given fileModeClass, if false it will NOT be writable.

isExecutable

public boolean isExecutable(FileAccessClass fileModeClass)
This method determines if this mask is executable for the given fileModeClass.

Parameters:
fileModeClass - is the class of access ( FileAccessClass.USER, FileAccessClass.GROUP, or FileAccessClass.OTHERS).
Returns:
true if the mask is executable for the given fileModeClass, false otherwise.

setExecutable

public void setExecutable(boolean executable)
This method sets the executable flag of this this mask for ALL access-classes to the given value (executable).

Parameters:
executable - if true the mask will be executable, if false it will NOT be executable.

setExecutable

public void setExecutable(FileAccessClass fileModeClass,
                          boolean executable)
This method sets the executable flag of this this mask for the given fileModeClass to the given value (executable).

Parameters:
fileModeClass - is the class of access ( FileAccessClass.USER, FileAccessClass.GROUP, or FileAccessClass.OTHERS).
executable - if true the mask will be executable for the given fileModeClass, if false it will NOT be executable.

isSetuid

public boolean isSetuid()
This method determines the value of the setuid flag ("set user ID"). If this flag is set and the file is executed, the according process will be started under the user of the file-owner instead of the user that performed the execution.

Returns:
true if the flag is set, false otherwise.

setSetuid

public void setSetuid(boolean setuid)
This method sets the setuid flag to the given value setuid.

Parameters:
setuid - - if true the flag will be set, if false it will be unset.

isSetgid

public boolean isSetgid()
This method determines the value of the setgid flag ("set group ID"). If this flag is set and the file is executed, the according process will be started under the group owning the file instead of the group of the user that performed the execution.

Returns:
true if the flag is set, false otherwise.

setSetgid

public void setSetgid(boolean setgid)
This method sets the setuid flag to the given value setuid.

Parameters:
setgid - - if true the flag will be set, if false it will be unset.

isSticky

public boolean isSticky()
This method determines the value of the sticky flag. This flag is mostly obsolete and is NOT used on linux systems.

Returns:
true if the flag is set, false otherwise.

setSticky

public void setSticky(boolean sticky)
This method sets the sticky flag to the given value sticky.

Parameters:
sticky - - if true the flag will be set, if false it will be unset.

shiftMask

private int shiftMask(FileAccessClass fileModeClass,
                      int bitMask)
This method shifts the given bitMask according to the given fileModeClass.

Parameters:
fileModeClass - is the class of access ( FileAccessClass.USER, FileAccessClass.GROUP, or FileAccessClass.OTHERS).
bitMask - is the bit-mask to shift.
Returns:
the shifted bitMask.

setFlag

private void setFlag(FileAccessClass fileModeClass,
                     int bitMask,
                     boolean flag)
This method sets the flag(s) given by bitMask of this this mask for the given fileModeClass to the given value (flag).

Parameters:
fileModeClass - is the class of access ( FileAccessClass.USER, FileAccessClass.GROUP, or FileAccessClass.OTHERS).
bitMask - is the bit-mask of the flag(s) to set.
flag - - if true the flag will be set, if false it will be unset.

hasFlag

private boolean hasFlag(FileAccessClass fileModeClass,
                        int bitMask)
This method determines if the flag(s) given by bitMask is set in this mask for the given fileModeClass.

Parameters:
fileModeClass - is the class of access ( FileAccessClass.USER, FileAccessClass.GROUP, or FileAccessClass.OTHERS).
bitMask - is the bit-mask of the flag(s) to get.
Returns:
true if the flag is set, false otherwise.

hasBits

private boolean hasBits(int bitMask)
This method determines if the flags given by bitMask are set in this mask.

Parameters:
bitMask - is the bit-mask of the flag(s) to check.
Returns:
true if the flags are set, false otherwise.

setBits

private void setBits(int bitMask,
                     boolean set)
This method sets or unsets the flags given by bitMask in this mask according to the given flag.

Parameters:
bitMask - is the bit-mask of the flag(s) to set or unset.
set - - if true the flag(s) will be set, if false they will be unset.

parseUGO

private static int parseUGO(CharSequenceScanner parse)
This method parses the ugoa prefix indicating which flags to modify.

Parameters:
parse - is the current state of the parser.
Returns:
the bit-mask with the UGO-flags.

parseSymbolicMode

private static int parseSymbolicMode(CharSequenceScanner parse,
                                     int maskBits)
This method parses a symbolic-mode segment from parse. It applies the chmod of that segment to the given mask and returns the result. The state of this object remains unchanged.

Parameters:
parse - is the current state of the parser.
maskBits - is the current modifier mask.
Returns:
the changed mask.

parseOctalMode

private static int parseOctalMode(CharSequenceScanner parse)
                           throws IllegalArgumentException
This method parses the current state of the chmod argument given by parse in octal mode. If no digits are detected, parse remains unchanged and -1 is returned, else all digits are consumed and the parsed octal-mode is returned.

Parameters:
parse - is the current parser state of the the chmod argument.
Returns:
the parsed octal-mode or -1 if parse does NOT point to a digit.
Throws:
IllegalArgumentException - if there are more the 4 digits or non-octal digits (8 or 9).

chmod

public void chmod(String chmod)
This method allows to change the modifiers by a string expression. It behaves like the GNU command chmod (change modifiers).
Examples:

Parameters:
chmod - is the mode-list argument as supplied to the chmod command. It can either be a single octal-mode (up to 4 digits of octal number) or a comma-separated list of symbolic-modes ([ugoa]*([-+=]([rwxXst]*|[ugo]))+).

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

clone

public FileAccessPermissions clone()

Overrides:
clone in class Object

toString

public String toString()

Overrides:
toString in class Object


Copyright © 2001-2010 mmm-Team. All Rights Reserved.