Class UnixFileSystem


  • public class UnixFileSystem
    extends java.lang.Object
    Collection of static methods to access Unix-specific file operations and information.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  UnixFileSystem.FileInformation
      Holds Unix-specific information about a file.
    • Constructor Summary

      Constructors 
      Constructor Description
      UnixFileSystem()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean createLink​(java.lang.String destFileName, java.io.File linkFile)
      Create a symbolic link on Unix.
      static java.io.File findExecutableInPath​(java.lang.String executable)
      Returns the absolute path of an executable if it is located on the path.
      static UnixFileSystem.FileInformation getFileInformation​(java.io.File file)
      Get Unix-specific information about a file.
      static java.lang.String getShell()
      Returns the shell executable of the current user.
      static boolean setMode​(int intMode, java.io.File destFile)
      Set the Unix file mode for a file.
      static boolean setMode​(java.lang.String mode, java.io.File destFile)
      Set the Unix file mode for a file.
      static boolean setOwner​(java.lang.String owner, java.io.File file)
      Set the owner of a file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UnixFileSystem

        public UnixFileSystem()
    • Method Detail

      • setMode

        public static boolean setMode​(int intMode,
                                      java.io.File destFile)
        Set the Unix file mode for a file. For specifying integer file modes, you can use octal numbers by prefixing a "0".
        Parameters:
        intMode - the Unix file mode
        destFile - the file for which the mode should be set
        Returns:
        whether the operation was successful or not
      • setMode

        public static boolean setMode​(java.lang.String mode,
                                      java.io.File destFile)
        Set the Unix file mode for a file.
        Parameters:
        mode - the Unix file mode as an octal string, e.g. "755".
        destFile - the file for which the mode should be set
        Returns:
        whether the operation was successful or not
      • createLink

        public static boolean createLink​(java.lang.String destFileName,
                                         java.io.File linkFile)
        Create a symbolic link on Unix. If the link exists it will be overwritten.
        Parameters:
        destFileName - the file where the link should point to
        linkFile - the link that should be created
        Returns:
        whether the operation was successful or not
      • setOwner

        public static boolean setOwner​(java.lang.String owner,
                                       java.io.File file)
        Set the owner of a file.
        Parameters:
        owner - the owner spec. Either a user name like "user" or a user name followed by a colon and a group name, like "user:group". In tha latter case, "user" can be the empty string and only the group ownership will be changed.
        file - the file for which the owner should be set.
        Returns:
        whether the operation was successful or not
      • getFileInformation

        public static UnixFileSystem.FileInformation getFileInformation​(java.io.File file)
        Get Unix-specific information about a file.
        Parameters:
        file - the file for which the information is requested.
        Returns:
        the FileInformation object with the Unix-specific information
      • findExecutableInPath

        public static java.io.File findExecutableInPath​(java.lang.String executable)
        Returns the absolute path of an executable if it is located on the path.
        Parameters:
        executable - the executable name without path information or quotes
        Returns:
        the path of the executable or null if the executable was not found.
      • getShell

        public static java.lang.String getShell()
        Returns the shell executable of the current user. If the SHELL environment variable is set, its value is returned, otherwise the return value is /bin/sh