- 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 class
PosixFile.CryptAlgorithm
The set of supported crypt algorithms.static class
PosixFile.SecuredDirectory
TODO: Java 1.8: Can do this in a pure Java way
-
Field Summary
Fields Modifier and Type Field Description static long
GROUP_EXECUTE
Group execute permissions.static long
GROUP_READ
Group read permissions.static long
GROUP_WRITE
Group write permissions.static long
IS_BLOCK_DEVICE
Is a block device.static long
IS_CHARACTER_DEVICE
Is a character special device.static long
IS_DIRECTORY
Is a directory.static long
IS_FIFO
Is a FIFO.static long
IS_REGULAR_FILE
Is a regular file.static long
IS_SOCKET
Is a socket.static long
IS_SYM_LINK
Is a symbolic link.static long
NOT_GROUP_EXECUTE
static long
NOT_GROUP_READ
static long
NOT_GROUP_WRITE
static long
NOT_OTHER_EXECUTE
static long
NOT_OTHER_READ
static long
NOT_OTHER_WRITE
static long
NOT_SAVE_TEXT_IMAGE
static long
NOT_SET_GID
static long
NOT_SET_UID
static long
NOT_USER_EXECUTE
static long
NOT_USER_READ
static long
NOT_USER_WRITE
static long
OTHER_EXECUTE
World execute permissions.static long
OTHER_READ
World read permission.static long
OTHER_WRITE
World write permissions.protected String
path
The path.static long
PERMISSION_MASK
The mode mask for just the file permissions.static int
ROOT_GID
The GID of the root user.static int
ROOT_UID
The UID of the root user.static long
SAVE_TEXT_IMAGE
Save text image.static long
SET_GID
Set GID on execute.static long
SET_UID
Set UID on execute.static long
TYPE_MASK
The mode mask for just the file type.static long
USER_EXECUTE
Owner execute permissions.static long
USER_READ
Owner read permissions.static long
USER_WRITE
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 performedPosixFile(PosixFile parent, String path, boolean strict)
Creates a new POSIX file.PosixFile(File file)
Creates a new POSIX file.PosixFile(File parent, String filename)
Creates a new POSIX file.PosixFile(String path)
Creates a new POSIX file.PosixFile(String parent, String filename)
Creates a new POSIX file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
checkRead()
Ensures that the calling thread is allowed to read thisPosixFile
in any way.static void
checkRead(String path)
Ensures that the calling thread is allowed to read thispath
in any way.void
checkWrite()
Ensures that the calling thread is allowed to write to or modify thisPosixFile
in any way.static void
checkWrite(String path)
Ensures that the calling thread is allowed to write to or modify thispath
in any way.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
contentEquals(PosixFile otherFile)
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.Please provide the algorithm and callcrypt(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 defaultSecureRandom
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.Please provide the algorithm and callcrypt(java.lang.String, com.aoapps.io.posix.PosixFile.CryptAlgorithm, java.security.SecureRandom)
instead.void
delete()
Deletes this file.void
deleteRecursive()
Deletes this file and if it is a directory, all files below it.boolean
equals(Object obj)
boolean
exists()
Deprecated.Please use getStat(Stat).exists()long
getAccessTime()
Deprecated.Please use getStat(Stat).getAccessTime()long
getBlockCount()
Deprecated.Please use getStat(State).getBlockCount()int
getBlockSize()
Deprecated.Please use getStat(Stat).getBlockSize()long
getChangeTime()
Deprecated.Please use getStat(Stat).getChangeTime()long
getDevice()
Deprecated.Please use getStat(Stat).getDevice()long
getDeviceIdentifier()
Deprecated.Please use getStat(Stat).getDeviceIdentifier()String
getExtension()
Gets the extension for this file.File
getFile()
Gets theFile
for thisPosixFile
.String
getFilename()
Deprecated.the use of the wordfilename
is misleading since it represents the entire path, please usegetPath()
instead.int
getGid()
Deprecated.Please use getStat(Stat).getGid()long
getInode()
Deprecated.Please use getStat(Stat).getInode()int
getLinkCount()
Deprecated.Please use getStat(Stat).getNumberLinks()long
getMode()
Deprecated.Please use getStat(Stat).getMode()String
getModeString()
Deprecated.Please use getStat(Stat).getModeString()static String
getModeString(long mode)
Gets a String representation of a mode similar to the output of the POSIXls
command.long
getModifyTime()
Deprecated.Please use getStat(Stat).getModifyTime()PosixFile
getParent()
Gets the parent of this file ornull
if it doesn't have a parent.String
getPath()
Gets the path for thisPosixFile
.FileInputStream
getSecureInputStream(int uidMin, int gidMin)
Securely gets aFileInputStream
to this file, temporarily performing permission changes and ensuring that no symbolic links are anywhere in the path.FileOutputStream
getSecureOutputStream(int uid, int gid, long mode, boolean overwrite, int uidMin, int gidMin)
Securely gets aFileOutputStream
to this file, temporarily performing permission changes and ensuring that no symbolic links are anywhere in the path.RandomAccessFile
getSecureRandomAccessFile(String mode, int uidMin, int gidMin)
Securely gets aRandomAccessFile
to this file, temporarily performing permission changes and ensuring that no symbolic links are anywhere in the path.long
getSize()
Deprecated.Please use getStat(Stat).getSize()Stat
getStat()
Stats the file.long
getStatMode()
Deprecated.Please use getStat(Stat).getRawMode()int
getUid()
Deprecated.Please use getStat(Stat).getUid()int
hashCode()
boolean
isBlockDevice()
Deprecated.Please use getStat(Stat).isBlockDevice()static boolean
isBlockDevice(long mode)
Determines if a specific mode represents a block device.boolean
isCharacterDevice()
Deprecated.Please use getStat(Stat).isCharacterDevice()static boolean
isCharacterDevice(long mode)
Determines if a specific mode represents a character device.boolean
isDirectory()
Deprecated.Please use getStat(Stat).isDirectory()static boolean
isDirectory(long mode)
Determines if a specific mode represents a directory.boolean
isFifo()
Deprecated.Please use getStat(Stat).isFifo()static boolean
isFifo(long mode)
Determines if a specific mode represents a FIFO.boolean
isRegularFile()
Deprecated.Please use getStat(Stat).isRegularFile()static boolean
isRegularFile(long mode)
Determines if a specific mode represents a regular file.boolean
isRootDirectory()
Determines if this file is the root directory.boolean
isSocket()
Deprecated.Please use getStat(Stat).isSocket()static boolean
isSocket(long mode)
Determines if a specific mode represents a socket.boolean
isSymLink()
Deprecated.Please use getStat(Stat).isSymLink()static boolean
isSymLink(long mode)
Determines if a specific mode represents a symbolic link.PosixFile
link(PosixFile destination)
Creates a hard link.PosixFile
link(String destination)
Creates a hard link.String[]
list()
Lists the contents of the directory.static void
loadLibrary()
Loads the shared library native codelibaocode.so
.PosixFile
mkdir()
Creates a directory.PosixFile
mkdir(boolean makeParents, long mode)
Creates a directory and sets its permissions, optionally creating all the parent directories if they do not exist.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.PosixFile
mkfifo(long mode)
Creates a FIFO.PosixFile
mknod(long mode, long device)
Creates a device file.static PosixFile
mktemp(String template)
static PosixFile
mktemp(String template, boolean deleteOnExit)
Deprecated.Please useFiles.createTempFile(java.lang.String, java.lang.String, java.nio.file.attribute.FileAttribute...)
or TempFileContext asFile.deleteOnExit()
is prone to memory leaks in long-running applications.String
readLink()
Reads a symbolic link.void
renameTo(PosixFile uf)
Renames this file, possibly overwriting any previous file.void
restoreParents(List<PosixFile.SecuredDirectory> parentsChanged)
TODO: Java 1.8: Can do this in a pure Java wayboolean
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.void
secureDeleteRecursive(int uidMin, int gidMin)
Securely deletes this file entry and all files below it while not following symbolic links.void
secureParents(List<PosixFile.SecuredDirectory> parentsChanged, int uidMin, int gidMin)
TODO: Java 1.8: Can do this in a pure Java wayPosixFile
setAccessTime(long atime)
Deprecated.This method internally performs an extra stat.PosixFile
setGid(int gid)
Deprecated.This method internally performs an extra stat.PosixFile
setGID(int gid)
Deprecated.Please usesetGid(int)
instead.PosixFile
setMode(long mode)
Sets the permissions for this file.PosixFile
setModifyTime(long mtime)
Deprecated.This method internally performs an extra stat.PosixFile
setUid(int uid)
Deprecated.This method internally performs an extra stat.PosixFile
setUID(int uid)
Deprecated.Please usesetUid(int)
instead.PosixFile
symLink(String destination)
Creates a symbolic link.String
toString()
PosixFile
utime(long atime, long mtime)
Sets the access and modify times for this file.
-
-
-
Field Detail
-
ROOT_UID
public static final int ROOT_UID
The UID of the root user.Note: Copied to LinuxServerAccount.java to avoid interproject dependency.
- See Also:
- Constant Field Values
-
ROOT_GID
public static final int ROOT_GID
The GID of the root user.- See Also:
- Constant Field Values
-
PERMISSION_MASK
public static final long PERMISSION_MASK
The mode mask for just the file permissions.- See Also:
- Constant Field Values
-
OTHER_EXECUTE
public static final long OTHER_EXECUTE
World execute permissions.- See Also:
- Constant Field Values
-
NOT_OTHER_EXECUTE
public static final long NOT_OTHER_EXECUTE
- See Also:
- Constant Field Values
-
OTHER_WRITE
public static final long OTHER_WRITE
World write permissions.- See Also:
- Constant Field Values
-
NOT_OTHER_WRITE
public static final long NOT_OTHER_WRITE
- See Also:
- Constant Field Values
-
OTHER_READ
public static final long OTHER_READ
World read permission.- See Also:
- Constant Field Values
-
NOT_OTHER_READ
public static final long NOT_OTHER_READ
- See Also:
- Constant Field Values
-
GROUP_EXECUTE
public static final long GROUP_EXECUTE
Group execute permissions.- See Also:
- Constant Field Values
-
NOT_GROUP_EXECUTE
public static final long NOT_GROUP_EXECUTE
- See Also:
- Constant Field Values
-
GROUP_WRITE
public static final long GROUP_WRITE
Group write permissions.- See Also:
- Constant Field Values
-
NOT_GROUP_WRITE
public static final long NOT_GROUP_WRITE
- See Also:
- Constant Field Values
-
GROUP_READ
public static final long GROUP_READ
Group read permissions.- See Also:
- Constant Field Values
-
NOT_GROUP_READ
public static final long NOT_GROUP_READ
- See Also:
- Constant Field Values
-
USER_EXECUTE
public static final long USER_EXECUTE
Owner execute permissions.- See Also:
- Constant Field Values
-
NOT_USER_EXECUTE
public static final long NOT_USER_EXECUTE
- See Also:
- Constant Field Values
-
USER_WRITE
public static final long USER_WRITE
Owner write permissions.- See Also:
- Constant Field Values
-
NOT_USER_WRITE
public static final long NOT_USER_WRITE
- See Also:
- Constant Field Values
-
USER_READ
public static final long USER_READ
Owner read permissions.- See Also:
- Constant Field Values
-
NOT_USER_READ
public static final long NOT_USER_READ
- See Also:
- Constant Field Values
-
SAVE_TEXT_IMAGE
public static final long SAVE_TEXT_IMAGE
Save text image.- See Also:
- Constant Field Values
-
NOT_SAVE_TEXT_IMAGE
public static final long NOT_SAVE_TEXT_IMAGE
- See Also:
- Constant Field Values
-
SET_GID
public static final long SET_GID
Set GID on execute.- See Also:
- Constant Field Values
-
NOT_SET_GID
public static final long NOT_SET_GID
- See Also:
- Constant Field Values
-
SET_UID
public static final long SET_UID
Set UID on execute.- See Also:
- Constant Field Values
-
NOT_SET_UID
public static final long NOT_SET_UID
- See Also:
- Constant Field Values
-
TYPE_MASK
public static final long TYPE_MASK
The mode mask for just the file type.- See Also:
- Constant Field Values
-
IS_FIFO
public static final long IS_FIFO
Is a FIFO.- See Also:
- Constant Field Values
-
IS_CHARACTER_DEVICE
public static final long IS_CHARACTER_DEVICE
Is a character special device.- See Also:
- Constant Field Values
-
IS_DIRECTORY
public static final long IS_DIRECTORY
Is a directory.- See Also:
- Constant Field Values
-
IS_BLOCK_DEVICE
public static final long IS_BLOCK_DEVICE
Is a block device.- See Also:
- Constant Field Values
-
IS_REGULAR_FILE
public static final long IS_REGULAR_FILE
Is a regular file.- See Also:
- Constant Field Values
-
IS_SYM_LINK
public static final long IS_SYM_LINK
Is a symbolic link.- See Also:
- Constant Field Values
-
IS_SOCKET
public static final long IS_SOCKET
Is a socket.- See Also:
- Constant Field Values
-
path
protected final String path
The path.
-
-
Constructor Detail
-
PosixFile
@Deprecated public PosixFile(PosixFile parent, String path) throws IOException
Deprecated.Please call #PosixFile(PosixFile,String,boolean) to explicitly control whether strict parent checking is performedCreates 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(String path)
Creates a new POSIX file.
-
-
Method Detail
-
loadLibrary
public static void loadLibrary()
Loads the shared library native codelibaocode.so
.
-
checkRead
public final void checkRead() throws IOException
Ensures that the calling thread is allowed to read thisPosixFile
in any way.- Throws:
IOException
-
checkRead
public static void checkRead(String path) throws IOException
Ensures that the calling thread is allowed to read thispath
in any way.- Throws:
IOException
-
checkWrite
public final void checkWrite() throws IOException
Ensures that the calling thread is allowed to write to or modify thisPosixFile
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 thispath
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
@Deprecated public static String crypt(String password)
Deprecated.Please provide the algorithm and callcrypt(java.lang.String, com.aoapps.io.posix.PosixFile.CryptAlgorithm)
instead.Hashes a password using the MD5 crypt algorithm and a defaultSecureRandom
instance, which is not a strong instance to avoid blocking.
-
crypt
@Deprecated public static String crypt(String password, SecureRandom secureRandom)
Deprecated.Please provide the algorithm and callcrypt(java.lang.String, com.aoapps.io.posix.PosixFile.CryptAlgorithm, java.security.SecureRandom)
instead.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 defaultSecureRandom
instance, which is not a strong instance to avoid blocking.
-
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
public static String crypt(String password, String salt)
Hashes a password using the provided salt. The salt includes anysalt prefix
for the algorithm.Please refer to
man 3 crypt
for more details.
-
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:
File.delete()
-
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, usedeleteRecursive
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 public final boolean exists() throws IOException
Deprecated.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 public final long getAccessTime() throws IOException
Deprecated.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 public final long getBlockCount() throws IOException
Deprecated.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 public final int getBlockSize() throws IOException
Deprecated.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 public final long getChangeTime() throws IOException
Deprecated.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 public final long getDevice() throws IOException
Deprecated.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 public final long getDeviceIdentifier() throws IOException
Deprecated.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 theFile
for thisPosixFile
. Not synchronized because multiple instantiation is acceptable.
-
getFilename
@Deprecated public final String getFilename()
Deprecated.the use of the wordfilename
is misleading since it represents the entire path, please usegetPath()
instead.Gets the path for thisPosixFile
.- See Also:
getPath()
-
getPath
public final String getPath()
Gets the path for thisPosixFile
.
-
getGid
@Deprecated public final int getGid() throws IOException
Deprecated.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 public final long getInode() throws IOException
Deprecated.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 public final int getLinkCount() throws IOException
Deprecated.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 public final long getMode() throws IOException
Deprecated.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 POSIXls
command.
-
getModeString
@Deprecated public final String getModeString() throws IOException
Deprecated.Please use getStat(Stat).getModeString()Gets a String representation of the mode of this file similar to the output of the POSIXls
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 aFileInputStream
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 aFileOutputStream
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 aRandomAccessFile
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 ornull
if it doesn't have a parent. Not synchronized because multiple instantiation is acceptable.
-
getStatMode
@Deprecated public final long getStatMode() throws IOException
Deprecated.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 public final long getModifyTime() throws IOException
Deprecated.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 public final long getSize() throws IOException
Deprecated.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 public static PosixFile mktemp(String template) throws IOException
Deprecated.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(String, boolean)
-
mktemp
@Deprecated public static PosixFile mktemp(String template, boolean deleteOnExit) throws IOException
Deprecated.Please useFiles.createTempFile(java.lang.String, java.lang.String, java.nio.file.attribute.FileAttribute...)
or TempFileContext asFile.deleteOnExit()
is prone to memory leaks in long-running applications.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 public final int getUid() throws IOException
Deprecated.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 public final boolean isBlockDevice() throws IOException
Deprecated.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 public final boolean isCharacterDevice() throws IOException
Deprecated.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 public final boolean isDirectory() throws IOException
Deprecated.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 public final boolean isFifo() throws IOException
Deprecated.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 public final boolean isRegularFile() throws IOException
Deprecated.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 public final boolean isSocket() throws IOException
Deprecated.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 public final boolean isSymLink() throws IOException
Deprecated.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:
File.list()
-
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 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 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 public final PosixFile setGID(int gid) throws IOException
Deprecated.Please usesetGid(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 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 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 public final PosixFile setUID(int uid) throws IOException
Deprecated.Please usesetUid(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:
File.renameTo(File)
-
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
-
-