Class PosixFile

java.lang.Object
com.aoapps.io.posix.PosixFile

public class PosixFile extends Object
Access and modify all the POSIX-specific file attributes. These updates are made using a Linux shared library provided as a resource. The source code is also supplied.

Note: The JVM must be in a single-byte locale, such as "C", "POSIX", or "en_US". PosixFile makes this assumption in its JNI implementation.

Author:
AO Industries, Inc.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The set of supported crypt algorithms.
    static class 
    TODO: Java 1.8: Can do this in a pure Java way.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Group execute permissions.
    static final long
    Group read permissions.
    static final long
    Group write permissions.
    static final long
    Is a block device.
    static final long
    Is a character special device.
    static final long
    Is a directory.
    static final long
    Is a FIFO.
    static final long
    Is a regular file.
    static final long
    Is a socket.
    static final long
    Is a symbolic link.
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
    World execute permissions.
    static final long
    World read permission.
    static final long
    World write permissions.
    protected final String
    The path.
    static final long
    The mode mask for just the file permissions.
    static final int
    The GID of the root user.
    static final int
    The UID of the root user.
    static final long
    Save text image.
    static final long
    Set GID on execute.
    static final long
    Set UID on execute.
    static final long
    The mode mask for just the file type.
    static final long
    Owner execute permissions.
    static final long
    Owner read permissions.
    static final long
    Owner write permissions.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PosixFile(PosixFile parent, String path)
    Deprecated.
    Please call #PosixFile(PosixFile,String,boolean) to explicitly control whether strict parent checking is performed
    PosixFile(PosixFile parent, String path, boolean strict)
    Creates a new POSIX file.
    Creates a new POSIX file.
    PosixFile(File parent, String filename)
    Creates a new POSIX file.
    Creates a new POSIX file.
    PosixFile(String parent, String filename)
    Creates a new POSIX file.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    Ensures that the calling thread is allowed to read this PosixFile in any way.
    static void
    Ensures that the calling thread is allowed to read this path in any way.
    final void
    Ensures that the calling thread is allowed to write to or modify this PosixFile in any way.
    static void
    Ensures that the calling thread is allowed to write to or modify this path in any way.
    final PosixFile
    chown(int uid, int gid)
    Changes both the owner and group for a file.
    boolean
    contentEquals(byte[] otherFile)
    Compares the contents of a file to a byte[].
    boolean
    Compares this contents of this file to the contents of another file.
    void
    copyTo(PosixFile otherFile, boolean overwrite)
    Copies one filesystem object to another.
    static String
    crypt(String password)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please provide the algorithm and call crypt(java.lang.String, com.aoapps.io.posix.PosixFile.CryptAlgorithm) instead.
    static String
    crypt(String password, PosixFile.CryptAlgorithm algorithm)
    Hashes a password using the provided crypt algorithm and a default SecureRandom instance, which is not a strong instance to avoid blocking.
    static String
    crypt(String password, PosixFile.CryptAlgorithm algorithm, SecureRandom secureRandom)
    Hashes a password using the provided crypt algorithm and the provided random source.
    static String
    crypt(String password, String salt)
    Hashes a password using the provided salt.
    static String
    crypt(String password, SecureRandom secureRandom)
    Deprecated, for removal: This API element is subject to removal in a future version.
    final void
    Deletes this file.
    final void
    Deletes this file and if it is a directory, all files below it.
    boolean
     
    final boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).exists()
    final long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getAccessTime()
    final long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(State).getBlockCount()
    final int
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getBlockSize()
    final long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getChangeTime()
    final long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getDevice()
    final long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getDeviceIdentifier()
    final String
    Gets the extension for this file.
    final File
    Gets the File for this PosixFile.
    final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    the use of the word filename is misleading since it represents the entire path, please use getPath() instead.
    final int
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getGid()
    final long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getInode()
    final int
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getNumberLinks()
    final long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getMode()
    final String
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getModeString()
    static String
    getModeString(long mode)
    Gets a String representation of a mode similar to the output of the POSIX ls command.
    final long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getModifyTime()
    final PosixFile
    Gets the parent of this file or null if it doesn't have a parent.
    final String
    Gets the path for this PosixFile.
    getSecureInputStream(int uidMin, int gidMin)
    Securely gets a FileInputStream to this file, temporarily performing permission changes and ensuring that no symbolic links are anywhere in the path.
    getSecureOutputStream(int uid, int gid, long mode, boolean overwrite, int uidMin, int gidMin)
    Securely gets a FileOutputStream to this file, temporarily performing permission changes and ensuring that no symbolic links are anywhere in the path.
    getSecureRandomAccessFile(String mode, int uidMin, int gidMin)
    Securely gets a RandomAccessFile to this file, temporarily performing permission changes and ensuring that no symbolic links are anywhere in the path.
    final long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getSize()
    Stats the file.
    final long
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getRawMode()
    final int
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).getUid()
    int
     
    final boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).isBlockDevice()
    static boolean
    isBlockDevice(long mode)
    Determines if a specific mode represents a block device.
    final boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).isCharacterDevice()
    static boolean
    isCharacterDevice(long mode)
    Determines if a specific mode represents a character device.
    final boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).isDirectory()
    static boolean
    isDirectory(long mode)
    Determines if a specific mode represents a directory.
    final boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).isFifo()
    static boolean
    isFifo(long mode)
    Determines if a specific mode represents a FIFO.
    final boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).isRegularFile()
    static boolean
    isRegularFile(long mode)
    Determines if a specific mode represents a regular file.
    final boolean
    Determines if this file is the root directory.
    final boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).isSocket()
    static boolean
    isSocket(long mode)
    Determines if a specific mode represents a socket.
    final boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use getStat(Stat).isSymLink()
    static boolean
    isSymLink(long mode)
    Determines if a specific mode represents a symbolic link.
    final PosixFile
    link(PosixFile destination)
    Creates a hard link.
    final PosixFile
    link(String destination)
    Creates a hard link.
    final String[]
    Lists the contents of the directory.
    static void
    Loads the shared library native code libaocode.so.
    final PosixFile
    Creates a directory.
    final PosixFile
    mkdir(boolean makeParents, long mode)
    Creates a directory and sets its permissions, optionally creating all the parent directories if they do not exist.
    final PosixFile
    mkdir(boolean makeParents, long mode, int uid, int gid)
    Creates a directory and sets its permissions, optionally creating all the parent directories if they do not exist.
    final PosixFile
    mkfifo(long mode)
    Creates a FIFO.
    final PosixFile
    mknod(long mode, long device)
    Creates a device file.
    static PosixFile
    mktemp(String template)
    Deprecated, for removal: This API element is subject to removal in a future version.
    static PosixFile
    mktemp(String template, boolean deleteOnExit)
    Deprecated, for removal: This API element is subject to removal in a future version.
    final String
    Reads a symbolic link.
    final void
    Renames this file, possibly overwriting any previous file.
    final void
    TODO: Java 1.8: Can do this in a pure Java way.
    boolean
    secureContentEquals(byte[] otherFile, int uidMin, int gidMin)
    Compares the contents of a file to a byte[].
    boolean
    secureContentEquals(PosixFile otherFile, int uidMin, int gidMin)
    Compares this contents of this file to the contents of another file.
    final void
    secureDeleteRecursive(int uidMin, int gidMin)
    Securely deletes this file entry and all files below it while not following symbolic links.
    final void
    secureParents(List<PosixFile.SecuredDirectory> parentsChanged, int uidMin, int gidMin)
    TODO: Java 1.8: Can do this in a pure Java way.
    final PosixFile
    setAccessTime(long atime)
    Deprecated.
    This method internally performs an extra stat.
    final PosixFile
    setGid(int gid)
    Deprecated.
    This method internally performs an extra stat.
    final PosixFile
    setGID(int gid)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use setGid(int) instead.
    final PosixFile
    setMode(long mode)
    Sets the permissions for this file.
    final PosixFile
    setModifyTime(long mtime)
    Deprecated.
    This method internally performs an extra stat.
    final PosixFile
    setUid(int uid)
    Deprecated.
    This method internally performs an extra stat.
    final PosixFile
    setUID(int uid)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use setUid(int) instead.
    final PosixFile
    symLink(String destination)
    Creates a symbolic link.
    final String
     
    final PosixFile
    utime(long atime, long mtime)
    Sets the access and modify times for this file.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • PosixFile

      @Deprecated(forRemoval=false) public PosixFile(PosixFile parent, String path) throws IOException
      Deprecated.
      Please call #PosixFile(PosixFile,String,boolean) to explicitly control whether strict parent checking is performed
      Creates a new POSIX file.

      Strictly requires the parent to be a directory if it exists.

      Throws:
      IOException
    • PosixFile

      public PosixFile(PosixFile parent, String path, boolean strict) throws IOException
      Creates a new POSIX file.
      Parameters:
      strict - When strictly checking, a parent must be a directory if it exists.
      Throws:
      IOException
    • PosixFile

      public PosixFile(File file)
      Creates a new POSIX file.
    • PosixFile

      public PosixFile(File parent, String filename)
      Creates a new POSIX file.
    • PosixFile

      public PosixFile(String path)
      Creates a new POSIX file.
    • PosixFile

      public PosixFile(String parent, String filename)
      Creates a new POSIX file.
  • Method Details

    • loadLibrary

      public static void loadLibrary()
      Loads the shared library native code libaocode.so.
    • checkRead

      public final void checkRead() throws IOException
      Ensures that the calling thread is allowed to read this PosixFile in any way.
      Throws:
      IOException
    • checkRead

      public static void checkRead(String path) throws IOException
      Ensures that the calling thread is allowed to read this path in any way.
      Throws:
      IOException
    • checkWrite

      public final void checkWrite() throws IOException
      Ensures that the calling thread is allowed to write to or modify this PosixFile in any way.
      Throws:
      IOException
    • checkWrite

      public static void checkWrite(String path) throws IOException
      Ensures that the calling thread is allowed to write to or modify this path in any way.
      Throws:
      IOException
    • chown

      public final PosixFile chown(int uid, int gid) throws IOException
      Changes both the owner and group for a file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getStat

      public Stat getStat() throws IOException
      Stats the file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • contentEquals

      public boolean contentEquals(PosixFile otherFile) throws IOException
      Compares this contents of this file to the contents of another file.

      This method will follow both path symbolic links and a final symbolic link.

      Throws:
      IOException
    • contentEquals

      public boolean contentEquals(byte[] otherFile) throws IOException
      Compares the contents of a file to a byte[].

      This method will follow both path symbolic links and a final symbolic link.

      Throws:
      IOException
    • secureContentEquals

      public boolean secureContentEquals(PosixFile otherFile, int uidMin, int gidMin) throws IOException
      Compares this contents of this file to the contents of another file.

      This method will not follow any symbolic links and is not subject to race conditions.

      TODO: Java 1.8: Can do this in a pure Java way

      Throws:
      IOException
    • secureContentEquals

      public boolean secureContentEquals(byte[] otherFile, int uidMin, int gidMin) throws IOException
      Compares the contents of a file to a byte[].

      This method will not follow any symbolic links and is not subject to race conditions.

      TODO: Java 1.8: Can do this in a pure Java way

      Throws:
      IOException
    • copyTo

      public void copyTo(PosixFile otherFile, boolean overwrite) throws IOException
      Copies one filesystem object to another. It supports block devices, directories, fifos, regular files, and symbolic links. Directories are not copied recursively.

      This method will follow both path symbolic links and a final symbolic link.

      Throws:
      IOException
    • crypt

      public static String crypt(String password, String salt)
      Hashes a password using the provided salt. The salt includes any salt prefix for the algorithm.

      Please refer to man 3 crypt for more details.

    • crypt

      public static String crypt(String password, PosixFile.CryptAlgorithm algorithm, SecureRandom secureRandom)
      Hashes a password using the provided crypt algorithm and the provided random source.
    • crypt

      @Deprecated(forRemoval=true) public static String crypt(String password)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please provide the algorithm and call crypt(java.lang.String, com.aoapps.io.posix.PosixFile.CryptAlgorithm) instead.
      Hashes a password using the MD5 crypt algorithm and a default SecureRandom instance, which is not a strong instance to avoid blocking.
    • crypt

      @Deprecated(forRemoval=true) public static String crypt(String password, SecureRandom secureRandom)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Hashes a password using the MD5 crypt algorithm and the provided random source.
    • crypt

      public static String crypt(String password, PosixFile.CryptAlgorithm algorithm)
      Hashes a password using the provided crypt algorithm and a default SecureRandom instance, which is not a strong instance to avoid blocking.
    • delete

      public final void delete() throws IOException
      Deletes this file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
      See Also:
    • deleteRecursive

      public final void deleteRecursive() throws IOException
      Deletes this file and if it is a directory, all files below it.

      Due to a race conditition, this method will follow symbolic links. Please use secureDeleteRecursive instead.

      Throws:
      IOException
      See Also:
      • deleteRecursive(com.aoapps.io.posix.PosixFile)
    • secureParents

      public final void secureParents(List<PosixFile.SecuredDirectory> parentsChanged, int uidMin, int gidMin) throws IOException
      TODO: Java 1.8: Can do this in a pure Java way.
      Throws:
      IOException
    • restoreParents

      public final void restoreParents(List<PosixFile.SecuredDirectory> parentsChanged) throws IOException
      TODO: Java 1.8: Can do this in a pure Java way.
      Throws:
      IOException
    • secureDeleteRecursive

      public final void secureDeleteRecursive(int uidMin, int gidMin) throws IOException
      Securely deletes this file entry and all files below it while not following symbolic links. This method must be called with root privileges to properly avoid race conditions. If not running with root privileges, use deleteRecursive instead.

      In order to avoid race conditions, all directories above this directory will have their permissions set so that regular users cannot modify the directories. After each parent directory has its permissions set it will then check for symbolic links. Once all of the parent directories have been completed, the filesystem will recursively have its permissions reset, scans for symlinks, and deletes performed in such a way all race conditions are avoided. Finally, the parent directory permissions that were modified will be restored.

      TODO: Java 1.8: Can do this in a pure Java way

      Throws:
      IOException
      See Also:
      • secureDeleteRecursive(com.aoapps.io.posix.PosixFile)
    • exists

      @Deprecated(forRemoval=true) public final boolean exists() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).exists()
      Determines if a file exists, a symbolic link with an invalid destination is still considered to exist.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getAccessTime

      @Deprecated(forRemoval=true) public final long getAccessTime() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getAccessTime()
      Gets the last access to this file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getBlockCount

      @Deprecated(forRemoval=true) public final long getBlockCount() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(State).getBlockCount()
      Gets the block count for this file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getBlockSize

      @Deprecated(forRemoval=true) public final int getBlockSize() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getBlockSize()
      Gets the block size for this file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getChangeTime

      @Deprecated(forRemoval=true) public final long getChangeTime() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getChangeTime()
      Gets the change time of this file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getDevice

      @Deprecated(forRemoval=true) public final long getDevice() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getDevice()
      Gets the device for this file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getDeviceIdentifier

      @Deprecated(forRemoval=true) public final long getDeviceIdentifier() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getDeviceIdentifier()
      Gets the device identifier for this file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getExtension

      public final String getExtension()
      Gets the extension for this file.
    • getFile

      public final File getFile()
      Gets the File for this PosixFile. Not synchronized because multiple instantiation is acceptable.
    • getFilename

      @Deprecated(forRemoval=true) public final String getFilename()
      Deprecated, for removal: This API element is subject to removal in a future version.
      the use of the word filename is misleading since it represents the entire path, please use getPath() instead.
      Gets the path for this PosixFile.
      See Also:
    • getPath

      public final String getPath()
      Gets the path for this PosixFile.
    • getGid

      @Deprecated(forRemoval=true) public final int getGid() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getGid()
      Gets the group ID for this file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getInode

      @Deprecated(forRemoval=true) public final long getInode() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getInode()
      Gets the inode for this file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getLinkCount

      @Deprecated(forRemoval=true) public final int getLinkCount() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getNumberLinks()
      Gets the link count for this file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getMode

      @Deprecated(forRemoval=true) public final long getMode() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getMode()
      Gets the permission bits of the mode of this file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getModeString

      public static String getModeString(long mode)
      Gets a String representation of a mode similar to the output of the POSIX ls command.
    • getModeString

      @Deprecated(forRemoval=true) public final String getModeString() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getModeString()
      Gets a String representation of the mode of this file similar to the output of the POSIX ls command.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getSecureInputStream

      public final FileInputStream getSecureInputStream(int uidMin, int gidMin) throws IOException
      Securely gets a FileInputStream to this file, temporarily performing permission changes and ensuring that no symbolic links are anywhere in the path.

      TODO: Java 1.8: Can do this in a pure Java way

      Throws:
      IOException
    • getSecureOutputStream

      public final FileOutputStream getSecureOutputStream(int uid, int gid, long mode, boolean overwrite, int uidMin, int gidMin) throws IOException
      Securely gets a FileOutputStream to this file, temporarily performing permission changes and ensuring that no symbolic links are anywhere in the path.

      TODO: Consider the impact of using mktemp instead of secureParents/restoreParents because there is the possibility that permissions may not be restored if the JVM is shutdown at that moment.

      TODO: Java 1.8: Can do this in a pure Java way

      Throws:
      IOException
    • getSecureRandomAccessFile

      public final RandomAccessFile getSecureRandomAccessFile(String mode, int uidMin, int gidMin) throws IOException
      Securely gets a RandomAccessFile to this file, temporarily performing permission changes and ensuring that no symbolic links are anywhere in the path.

      TODO: Java 1.8: Can do this in a pure Java way

      Throws:
      IOException
    • getParent

      public final PosixFile getParent()
      Gets the parent of this file or null if it doesn't have a parent. Not synchronized because multiple instantiation is acceptable.
    • getStatMode

      @Deprecated(forRemoval=true) public final long getStatMode() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getRawMode()
      Gets the complete mode of the file, including the bits representing the file type.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getModifyTime

      @Deprecated(forRemoval=true) public final long getModifyTime() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getModifyTime()
      Gets the modification time of the file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getSize

      @Deprecated(forRemoval=true) public final long getSize() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getSize()
      Gets the size of the file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • mktemp

      @Deprecated(forRemoval=true) public static PosixFile mktemp(String template) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Securely creates a temporary file, not deleting on exit. In order to be secure, though, the directory needs to be secure, or at least have the sticky bit set.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
      See Also:
    • mktemp

      @Deprecated(forRemoval=true) public static PosixFile mktemp(String template, boolean deleteOnExit) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Securely creates a temporary file. In order to be secure, though, the directory needs to be secure, or at least have the sticky bit set.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • getUid

      @Deprecated(forRemoval=true) public final int getUid() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).getUid()
      Gets the user ID of the file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • isBlockDevice

      public static boolean isBlockDevice(long mode)
      Determines if a specific mode represents a block device.
    • isBlockDevice

      @Deprecated(forRemoval=true) public final boolean isBlockDevice() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).isBlockDevice()
      Determines if this file represents a block device.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • isCharacterDevice

      public static boolean isCharacterDevice(long mode)
      Determines if a specific mode represents a character device.
    • isCharacterDevice

      @Deprecated(forRemoval=true) public final boolean isCharacterDevice() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).isCharacterDevice()
      Determines if this file represents a character device.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • isDirectory

      public static boolean isDirectory(long mode)
      Determines if a specific mode represents a directory.
    • isDirectory

      @Deprecated(forRemoval=true) public final boolean isDirectory() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).isDirectory()
      Determines if this file represents a directory.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • isFifo

      public static boolean isFifo(long mode)
      Determines if a specific mode represents a FIFO.
    • isFifo

      @Deprecated(forRemoval=true) public final boolean isFifo() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).isFifo()
      Determines if this file represents a FIFO.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • isRegularFile

      public static boolean isRegularFile(long mode)
      Determines if a specific mode represents a regular file.
    • isRegularFile

      @Deprecated(forRemoval=true) public final boolean isRegularFile() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).isRegularFile()
      Determines if this file represents a regular file.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • isRootDirectory

      public final boolean isRootDirectory()
      Determines if this file is the root directory.
    • isSocket

      public static boolean isSocket(long mode)
      Determines if a specific mode represents a socket.
    • isSocket

      @Deprecated(forRemoval=true) public final boolean isSocket() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).isSocket()
      Determines if this file represents a socket.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • isSymLink

      public static boolean isSymLink(long mode)
      Determines if a specific mode represents a symbolic link.
    • isSymLink

      @Deprecated(forRemoval=true) public final boolean isSymLink() throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getStat(Stat).isSymLink()
      Determines if this file represents a sybolic link.

      This method will follow symbolic links in the path but not a final symbolic link.

      Throws:
      IOException
    • list

      public final String[] list()
      Lists the contents of the directory.

      This method will follow symbolic links in the path, including a final symbolic link.

      See Also:
    • mkdir

      public final PosixFile mkdir() throws IOException
      Creates a directory.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • mkdir

      public final PosixFile mkdir(boolean makeParents, long mode) throws IOException
      Creates a directory and sets its permissions, optionally creating all the parent directories if they do not exist.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • mkdir

      public final PosixFile mkdir(boolean makeParents, long mode, int uid, int gid) throws IOException
      Creates a directory and sets its permissions, optionally creating all the parent directories if they do not exist.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • mknod

      public final PosixFile mknod(long mode, long device) throws IOException
      Creates a device file.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • mkfifo

      public final PosixFile mkfifo(long mode) throws IOException
      Creates a FIFO.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • setAccessTime

      @Deprecated(forRemoval=false) public final PosixFile setAccessTime(long atime) throws IOException
      Deprecated.
      This method internally performs an extra stat. Please try to use utime(long,long) directly to avoid this extra stat.
      Sets the access time for this file.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • setGid

      @Deprecated(forRemoval=false) public final PosixFile setGid(int gid) throws IOException
      Deprecated.
      This method internally performs an extra stat. Please try to use chown(int,int) directly to avoid this extra stat.
      Sets the group ID for this file.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • setGID

      @Deprecated(forRemoval=true) public final PosixFile setGID(int gid) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use setGid(int) instead.
      Sets the group ID for this file.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • setMode

      public final PosixFile setMode(long mode) throws IOException
      Sets the permissions for this file.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • setModifyTime

      @Deprecated(forRemoval=false) public final PosixFile setModifyTime(long mtime) throws IOException
      Deprecated.
      This method internally performs an extra stat. Please try to use utime(long,long) directly to avoid this extra stat.
      Sets the modification time for this file.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • setUid

      @Deprecated(forRemoval=false) public final PosixFile setUid(int uid) throws IOException
      Deprecated.
      This method internally performs an extra stat. Please try to use chown(int,int) directly to avoid this extra stat.
      Sets the user ID for this file.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • setUID

      @Deprecated(forRemoval=true) public final PosixFile setUID(int uid) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use setUid(int) instead.
      Sets the user ID for this file.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • symLink

      public final PosixFile symLink(String destination) throws IOException
      Creates a symbolic link.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • link

      public final PosixFile link(PosixFile destination) throws IOException
      Creates a hard link.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • link

      public final PosixFile link(String destination) throws IOException
      Creates a hard link.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • readLink

      public final String readLink() throws IOException
      Reads a symbolic link.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • renameTo

      public final void renameTo(PosixFile uf) throws IOException
      Renames this file, possibly overwriting any previous file.

      This method will follow symbolic links in the path.

      Throws:
      IOException
      See Also:
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • utime

      public final PosixFile utime(long atime, long mtime) throws IOException
      Sets the access and modify times for this file.

      This method will follow symbolic links in the path.

      Throws:
      IOException
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object