Top Fields Constructors Methods
jnr.posix

public Class JavaSecuredFile

extends File
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.io.File, .FileFilter, .FilenameFilter, .IOException, java.net.URI

Field Summary

Inherited from java.io.File:
pathSeparatorpathSeparatorCharseparatorseparatorChar

Constructor Summary

AccessConstructor and Description
public
public
JavaSecuredFile(String parent, String child)

public
JavaSecuredFile(File parent, String child)

public

Method Summary

Modifier and TypeMethod and Description
public boolean
canRead()

Overrides java.io.File.canRead.

Tests whether the application can read the file denoted by this abstract pathname.
public boolean
canWrite()

Overrides java.io.File.canWrite.

Tests whether the application can modify the file denoted by this abstract pathname.
public boolean
createNewFile()

Overrides java.io.File.createNewFile.

Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.
public boolean
delete()

Overrides java.io.File.delete.

Deletes the file or directory denoted by this abstract pathname.
public boolean
exists()

Overrides java.io.File.exists.

Tests whether the file or directory denoted by this abstract pathname exists.
public File
getAbsoluteFile()

Overrides java.io.File.getAbsoluteFile.

Returns the absolute form of this abstract pathname.
public File
getCanonicalFile()

Overrides java.io.File.getCanonicalFile.

Returns the canonical form of this abstract pathname.
public String
getCanonicalPath()

Overrides java.io.File.getCanonicalPath.

Returns the canonical pathname string of this abstract pathname.
public File
getParentFile()

Overrides java.io.File.getParentFile.

Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.
public boolean
isDirectory()

Overrides java.io.File.isDirectory.

Tests whether the file denoted by this abstract pathname is a directory.
public boolean
isFile()

Overrides java.io.File.isFile.

Tests whether the file denoted by this abstract pathname is a normal file.
public boolean
isHidden()

Overrides java.io.File.isHidden.

Tests whether the file named by this abstract pathname is a hidden file.
public long
lastModified()

Overrides java.io.File.lastModified.

Returns the time that the file denoted by this abstract pathname was last modified.
public long
length()

Overrides java.io.File.length.

Returns the length of the file denoted by this abstract pathname.
public String[]
list()

Overrides java.io.File.list.

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.
public String[]
list(FilenameFilter
A filename filter
filter
)

Overrides java.io.File.list.

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
public File[]
listFiles()

Overrides java.io.File.listFiles.

Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.
public File[]
listFiles(FileFilter
A file filter
filter
)

Overrides java.io.File.listFiles.

Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
public boolean
mkdir()

Overrides java.io.File.mkdir.

Creates the directory named by this abstract pathname.
public boolean
mkdirs()

Overrides java.io.File.mkdirs.

Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories.
public boolean
renameTo(File
The new abstract pathname for the named file
dest
)

Overrides java.io.File.renameTo.

Renames the file denoted by this abstract pathname.
public boolean
setLastModified(long
The new last-modified time, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)
time
)

Overrides java.io.File.setLastModified.

Sets the last-modified time of the file or directory named by this abstract pathname.
public boolean
setReadOnly()

Overrides java.io.File.setReadOnly.

Marks the file or directory named by this abstract pathname so that only read operations are allowed.
Inherited from java.io.File:
canExecutecompareTocreateTempFilecreateTempFiledeleteOnExitequalsgetAbsolutePathgetFreeSpacegetNamegetParentgetPathgetTotalSpacegetUsableSpacehashCodeisAbsolutelistFileslistRootssetExecutablesetExecutablesetReadablesetReadablesetWritablesetWritabletoPathtoStringtoURItoURL

Constructor Detail

JavaSecuredFileback to summary
public JavaSecuredFile(String pathname)
JavaSecuredFileback to summary
public JavaSecuredFile(String parent, String child)
JavaSecuredFileback to summary
public JavaSecuredFile(File parent, String child)
JavaSecuredFileback to summary
public JavaSecuredFile(URI uri)

Method Detail

canReadback to summary
public boolean canRead()

Overrides java.io.File.canRead.

Doc from java.io.File.canRead.

Tests whether the application can read the file denoted by this abstract pathname. On some platforms it may be possible to start the Java virtual machine with special privileges that allow it to read files that are marked as unreadable. Consequently, this method may return true even though the file does not have read permissions.

Returns:boolean

true if and only if the file specified by this abstract pathname exists and can be read by the application; false otherwise

Annotations
@Override
canWriteback to summary
public boolean canWrite()

Overrides java.io.File.canWrite.

Doc from java.io.File.canWrite.

Tests whether the application can modify the file denoted by this abstract pathname. On some platforms it may be possible to start the Java virtual machine with special privileges that allow it to modify files that are marked read-only. Consequently, this method may return true even though the file is marked read-only.

Returns:boolean

true if and only if the file system actually contains a file denoted by this abstract pathname and the application is allowed to write to the file; false otherwise.

Annotations
@Override
createNewFileback to summary
public boolean createNewFile() throws IOException

Overrides java.io.File.createNewFile.

Doc from java.io.File.createNewFile.

Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file.

Note

this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The FileLock facility should be used instead.

Returns:boolean

true if the named file does not exist and was successfully created; false if the named file already exists

Annotations
@Override
Exceptions
IOException:
If an I/O error occurred
deleteback to summary
public boolean delete()

Overrides java.io.File.delete.

Doc from java.io.File.delete.

Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty in order to be deleted.

Note that the java.nio.file.Files class defines the delete method to throw an IOException when a file cannot be deleted. This is useful for error reporting and to diagnose why a file cannot be deleted.

Returns:boolean

true if and only if the file or directory is successfully deleted; false otherwise

Annotations
@Override
existsback to summary
public boolean exists()

Overrides java.io.File.exists.

Doc from java.io.File.exists.

Tests whether the file or directory denoted by this abstract pathname exists.

Returns:boolean

true if and only if the file or directory denoted by this abstract pathname exists; false otherwise

Annotations
@Override
getAbsoluteFileback to summary
public File getAbsoluteFile()

Overrides java.io.File.getAbsoluteFile.

Doc from java.io.File.getAbsoluteFile.

Returns the absolute form of this abstract pathname. Equivalent to new File(this.getAbsolutePath).

Returns:File

The absolute abstract pathname denoting the same file or directory as this abstract pathname

Annotations
@Override
getCanonicalFileback to summary
public File getCanonicalFile() throws IOException

Overrides java.io.File.getCanonicalFile.

Doc from java.io.File.getCanonicalFile.

Returns the canonical form of this abstract pathname. Equivalent to new File(this.getCanonicalPath).

Returns:File

The canonical pathname string denoting the same file or directory as this abstract pathname

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries
getCanonicalPathback to summary
public String getCanonicalPath() throws IOException

Overrides java.io.File.getCanonicalPath.

Doc from java.io.File.getCanonicalPath.

Returns the canonical pathname string of this abstract pathname.

A canonical pathname is both absolute and unique. The precise definition of canonical form is system-dependent. This method first converts this pathname to absolute form if necessary, as if by invoking the getAbsolutePath method, and then maps it to its unique form in a system-dependent way. This typically involves removing redundant names such as "." and ".." from the pathname, resolving symbolic links (on UNIX platforms), and converting drive letters to a standard case (on Microsoft Windows platforms).

Every pathname that denotes an existing file or directory has a unique canonical form. Every pathname that denotes a nonexistent file or directory also has a unique canonical form. The canonical form of the pathname of a nonexistent file or directory may be different from the canonical form of the same pathname after the file or directory is created. Similarly, the canonical form of the pathname of an existing file or directory may be different from the canonical form of the same pathname after the file or directory is deleted.

Returns:String

The canonical pathname string denoting the same file or directory as this abstract pathname

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries
getParentFileback to summary
public File getParentFile()

Overrides java.io.File.getParentFile.

Doc from java.io.File.getParentFile.

Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.

The parent of an abstract pathname consists of the pathname's prefix, if any, and each name in the pathname's name sequence except for the last. If the name sequence is empty then the pathname does not name a parent directory.

Returns:File

The abstract pathname of the parent directory named by this abstract pathname, or null if this pathname does not name a parent

Annotations
@Override
isDirectoryback to summary
public boolean isDirectory()

Overrides java.io.File.isDirectory.

Doc from java.io.File.isDirectory.

Tests whether the file denoted by this abstract pathname is a directory.

Where it is required to distinguish an I/O exception from the case that the file is not a directory, or where several attributes of the same file are required at the same time, then the Files.readAttributes method may be used.

Returns:boolean

true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise

Annotations
@Override
isFileback to summary
public boolean isFile()

Overrides java.io.File.isFile.

Doc from java.io.File.isFile.

Tests whether the file denoted by this abstract pathname is a normal file. A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file.

Where it is required to distinguish an I/O exception from the case that the file is not a normal file, or where several attributes of the same file are required at the same time, then the Files.readAttributes method may be used.

Returns:boolean

true if and only if the file denoted by this abstract pathname exists and is a normal file; false otherwise

Annotations
@Override
isHiddenback to summary
public boolean isHidden()

Overrides java.io.File.isHidden.

Doc from java.io.File.isHidden.

Tests whether the file named by this abstract pathname is a hidden file. The exact definition of hidden is system-dependent. On UNIX systems, a file is considered to be hidden if its name begins with a period character ('.'). On Microsoft Windows systems, a file is considered to be hidden if it has been marked as such in the filesystem.

Returns:boolean

true if and only if the file denoted by this abstract pathname is hidden according to the conventions of the underlying platform

Annotations
@Override
lastModifiedback to summary
public long lastModified()

Overrides java.io.File.lastModified.

Doc from java.io.File.lastModified.

Returns the time that the file denoted by this abstract pathname was last modified.

Returns:long

A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs. The value may be negative indicating the number of milliseconds before the epoch

Annotations
@Override
lengthback to summary
public long length()

Overrides java.io.File.length.

Doc from java.io.File.length.

Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.

Where it is required to distinguish an I/O exception from the case that 0L is returned, or where several attributes of the same file are required at the same time, then the Files.readAttributes method may be used.

Returns:long

The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist. Some operating systems may return 0L for pathnames denoting system-dependent entities such as devices or pipes.

Annotations
@Override
listback to summary
public String[] list()

Overrides java.io.File.list.

Doc from java.io.File.list.

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.

If this abstract pathname does not denote a directory, then this method returns null. Otherwise an array of strings is returned, one for each file or directory in the directory. Names denoting the directory itself and the directory's parent directory are not included in the result. Each string is a file name rather than a complete path.

There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.

Note that the java.nio.file.Files class defines the newDirectoryStream method to open a directory and iterate over the names of the files in the directory. This may use less resources when working with very large directories, and may be more responsive when working with remote directories.

Returns:String[]

An array of strings naming the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

Annotations
@Override
listback to summary
public String[] list(FilenameFilter filter)

Overrides java.io.File.list.

Doc from java.io.File.list.

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter. The behavior of this method is the same as that of the list() method, except that the strings in the returned array must satisfy the filter. If the given filter is null then all names are accepted. Otherwise, a name satisfies the filter if and only if the value true results when the FilenameFilter.accept(File, String) method of the filter is invoked on this abstract pathname and the name of a file or directory in the directory that it denotes.

Parameters
filter:FilenameFilter

A filename filter

Returns:String[]

An array of strings naming the files and directories in the directory denoted by this abstract pathname that were accepted by the given filter. The array will be empty if the directory is empty or if no names were accepted by the filter. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

Annotations
@Override
listFilesback to summary
public File[] listFiles()

Overrides java.io.File.listFiles.

Doc from java.io.File.listFiles.

Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.

If this abstract pathname does not denote a directory, then this method returns null. Otherwise an array of File objects is returned, one for each file or directory in the directory. Pathnames denoting the directory itself and the directory's parent directory are not included in the result. Each resulting abstract pathname is constructed from this abstract pathname using the File(File, String) constructor. Therefore if this pathname is absolute then each resulting pathname is absolute; if this pathname is relative then each resulting pathname will be relative to the same directory.

There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.

Note that the java.nio.file.Files class defines the newDirectoryStream method to open a directory and iterate over the names of the files in the directory. This may use less resources when working with very large directories.

Returns:File[]

An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

Annotations
@Override
listFilesback to summary
public File[] listFiles(FileFilter filter)

Overrides java.io.File.listFiles.

Doc from java.io.File.listFiles.

Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter. The behavior of this method is the same as that of the listFiles() method, except that the pathnames in the returned array must satisfy the filter. If the given filter is null then all pathnames are accepted. Otherwise, a pathname satisfies the filter if and only if the value true results when the FileFilter.accept(File) method of the filter is invoked on the pathname.

Parameters
filter:FileFilter

A file filter

Returns:File[]

An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

Annotations
@Override
mkdirback to summary
public boolean mkdir()

Overrides java.io.File.mkdir.

Doc from java.io.File.mkdir.

Creates the directory named by this abstract pathname.

Returns:boolean

true if and only if the directory was created; false otherwise

Annotations
@Override
mkdirsback to summary
public boolean mkdirs()

Overrides java.io.File.mkdirs.

Doc from java.io.File.mkdirs.

Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.

Returns:boolean

true if and only if the directory was created, along with all necessary parent directories; false otherwise

Annotations
@Override
renameToback to summary
public boolean renameTo(File dest)

Overrides java.io.File.renameTo.

Doc from java.io.File.renameTo.

Renames the file denoted by this abstract pathname.

Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful. As instances of File are immutable, this File object is not changed to name the destination file or directory.

Note that the java.nio.file.Files class defines the move method to move or rename a file in a platform independent manner.

Parameters
dest:File

The new abstract pathname for the named file

Returns:boolean

true if and only if the renaming succeeded; false otherwise

Annotations
@Override
setLastModifiedback to summary
public boolean setLastModified(long time)

Overrides java.io.File.setLastModified.

Doc from java.io.File.setLastModified.

Sets the last-modified time of the file or directory named by this abstract pathname.

All platforms support file-modification times to the nearest second, but some provide more precision. The argument will be truncated to fit the supported precision. If the operation succeeds and no intervening operations on the file take place, then the next invocation of the lastModified method will return the (possibly truncated) time argument that was passed to this method.

Parameters
time:long

The new last-modified time, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)

Returns:boolean

true if and only if the operation succeeded; false otherwise

Annotations
@Override
setReadOnlyback to summary
public boolean setReadOnly()

Overrides java.io.File.setReadOnly.

Doc from java.io.File.setReadOnly.

Marks the file or directory named by this abstract pathname so that only read operations are allowed. After invoking this method the file or directory will not change until it is either deleted or marked to allow write access. On some platforms it may be possible to start the Java virtual machine with special privileges that allow it to modify files that are marked read-only. Whether or not a read-only file or directory may be deleted depends upon the underlying system.

Returns:boolean

true if and only if the operation succeeded; false otherwise

Annotations
@Override