|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.mucommander.file.AbstractFile
public abstract class AbstractFile
AbstractFile is the superclass of all files.
AbstractFile classes should never be instanciated directly. Instead, the FileFactory getFile
methods should be used to get a file instance from a path or FileURL location.
FileFactory,
ProxyFile| Field Summary | |
|---|---|
static java.lang.String |
DEFAULT_SEPARATOR
Default path separator |
protected FileURL |
fileURL
URL representing this file |
static int |
IO_BUFFER_SIZE
Size of the read/write buffer |
static int |
MUST_HINT
Indicates copyTo(AbstractFile)/moveTo(AbstractFile) *must* be used to copy/move the file (e.g. |
static int |
MUST_NOT_HINT
Indicates copyTo(AbstractFile)/moveTo(AbstractFile) *must not* be used to copy/move the file (e.g. |
static int |
SHOULD_HINT
Indicates copyTo(AbstractFile)/moveTo(AbstractFile) *should* be used to copy/move the file (e.g. |
static int |
SHOULD_NOT_HINT
Indicates copyTo(AbstractFile)/moveTo(AbstractFile) *should not* be used to copy/move the file (default) |
protected static java.util.regex.Pattern |
windowsDriveRootPattern
Pattern matching Windows drive root folders, e.g. |
| Fields inherited from interface com.mucommander.file.PermissionTypes |
|---|
EXECUTE_PERMISSION, READ_PERMISSION, WRITE_PERMISSION |
| Fields inherited from interface com.mucommander.file.PermissionAccesses |
|---|
GROUP_ACCESS, OTHER_ACCESS, USER_ACCESS |
| Constructor Summary | |
|---|---|
protected |
AbstractFile(FileURL url)
Creates a new file instance with the given URL. |
| Method Summary | |
|---|---|
protected java.lang.String |
addTrailingSeparator(java.lang.String path)
Tests if the given path contains a trailing separator, and if not, adds one to the returned path. |
static java.lang.String |
calculateChecksum(java.io.InputStream in,
java.security.MessageDigest messageDigest)
Returns the checksum (also referred to as hash or digest) of the given InputStream
calculated by reading the stream and feeding the bytes to the given MessageDigest until EOF is
reached. |
java.lang.String |
calculateChecksum(java.security.MessageDigest messageDigest)
Returns a checksum of this file (also referred to as hash or digest) calculated by reading this file's contents and feeding the bytes to the given MessageDigest, until EOF is reached. |
java.lang.String |
calculateChecksum(java.lang.String algorithm)
Returns a checksum of this file (also referred to as hash or digest) calculated by reading this file's contents and feeding the bytes to the given MessageDigest, until EOF is reached. |
abstract boolean |
canChangeDate()
Returns true if this file's date can be changed using changeDate(long). |
abstract boolean |
canGetGroup()
Returns true if this file implementation is able to return some information about file groups, not
necessarily for all files or this file in particular but at least for some of them. |
abstract boolean |
canGetOwner()
Returns true if this file implementation is able to return some information about file owners, not
necessarily for all files or this file in particular but at least for some of them. |
abstract boolean |
canRunProcess()
Returns true if it's possible to run processes on the underlying file system. |
abstract boolean |
changeDate(long lastModified)
Changes last modified date and returns true if date was changed successfully, false
if the operation could not be completed, either because this method is not implemented for this file type, or
because of insufficient permissions or a low-level I/O error. |
abstract boolean |
changePermission(int access,
int permission,
boolean enabled)
Changes the specified permission bit. |
boolean |
changePermissions(FilePermissions permissions)
Convenience method that calls changePermissions(int) with the given permissions' int value. |
boolean |
changePermissions(int permissions)
Changes this file's permissions to the specified permissions int and returns true if
the operation was successful, false if at least one of the file permissions could not be changed. |
protected void |
checkCopyPrerequisites(AbstractFile destFile,
boolean allowCaseVariations)
Checks the prerequisites of a copy (or move) operation. |
protected void |
copyRecursively(AbstractFile sourceFile,
AbstractFile destFile)
Copies the source file to the destination one and recurses on directory contents. |
void |
copyStream(java.io.InputStream in,
boolean append)
Copies the contents of the given InputStream to this file. |
boolean |
copyTo(AbstractFile destFile)
Copies this file to a specified destination file, overwriting the destination if it exists. |
abstract void |
delete()
Deletes this file and this file only (does not recurse on folders). |
void |
deleteRecursively()
Deletes this file. |
protected void |
deleteRecursively(AbstractFile file)
Deletes the given file. |
boolean |
equals(java.lang.Object f)
Tests a file for equality: returns true if the given file has the same canonical path,
as returned by getCanonicalPath(). |
abstract boolean |
exists()
Returns true if this file exists. |
java.lang.String |
getAbsolutePath()
Returns the absolute path to this file: For local files, the sole path is returned, and not a URL with the scheme and host parts (e.g. |
java.lang.String |
getAbsolutePath(boolean appendSeparator)
Returns the absolute path to this file. |
AbstractFile |
getAncestor()
Returns the immediate ancestor of this AbstractFile if it has one, this otherwise:
if this file is a ProxyFile, returns the return value of ProxyFile.getProxiedFile()
if this file is not a ProxyFile, returns this
|
AbstractFile |
getAncestor(java.lang.Class abstractFileClass)
Returns the first ancestor of this file that is an instance of the given Class or of a subclass of the given Class, or this if this instance's class matches those criteria. |
AbstractFile |
getCanonicalFile()
Returns an AbstractFile representing the canonical path of this file, or this if the
absolute and canonical path of this file are identical.Note that the returned file may or may not exist, for example if this file is a symlink to a file that doesn't exist. |
java.lang.String |
getCanonicalPath()
Returns the canonical path to this file, resolving any symbolic links or '..' and '.' occurrences. |
java.lang.String |
getCanonicalPath(boolean appendSeparator)
Returns the canonical path to this file, resolving any symbolic links or '..' and '.' occurrences. |
abstract PermissionBits |
getChangeablePermissions()
Returns a bit mask describing the permission bits that can be changed on this file when calling changePermission(int, int, boolean) and changePermissions(int). |
AbstractFile |
getChild(java.lang.String relativePath)
Returns a child of this file, whose path is the concatenation of this file's path and the given relative path. |
int |
getCopyToHint(AbstractFile destFile)
Returns a hint that indicates whether the copyTo(AbstractFile) method should be used to
copy this file to the specified destination file, rather than copying the file 'manually', using
copyStream(InputStream, boolean), or getInputStream() and getOutputStream(boolean). |
abstract long |
getDate()
Returns this file's last modified date, in milliseconds since the epoch (00:00:00 GMT, January 1, 1970). |
AbstractFile |
getDirectChild(java.lang.String filename)
Returns a direct child of this file, whose path is the concatenation of this file's path and the given filename. |
java.lang.String |
getExtension()
Returns this file's extension, null if this file's name doesn't have an extension. |
static java.lang.String |
getExtension(java.lang.String filename)
Returns the given filename's extension, null if the filename doesn't have an extension. |
abstract long |
getFreeSpace()
Returns the free space (in bytes) on the disk/volume where this file is, -1 if this information is
not available. |
abstract java.lang.String |
getGroup()
Returns information about the group this file belongs to. |
javax.swing.Icon |
getIcon()
Returns an icon representing this file, using the default FileIconProvider
registered in FileFactory. |
javax.swing.Icon |
getIcon(java.awt.Dimension preferredResolution)
Returns an icon representing this file, using the default FileIconProvider
registered in FileFactory. |
abstract java.io.InputStream |
getInputStream()
Returns an InputStream to read the contents of this file. |
java.io.InputStream |
getInputStream(long offset)
Returns an InputStream to read this file's contents, starting at the specified offset (in bytes). |
java.net.URL |
getJavaNetURL()
Creates and returns a java.net.URL referring to the same location as the FileURL associated
with this AbstractFile. |
int |
getMoveToHint(AbstractFile destFile)
Returns a hint that indicates whether the moveTo(AbstractFile) method should be used to
move this file to the specified destination file, rather than moving the file using
copyStream(InputStream, boolean) or getInputStream() and getOutputStream(boolean). |
java.lang.String |
getName()
Returns this file's name. |
java.lang.String |
getNameWithoutExtension()
Returns the name of the file without its extension. |
abstract java.io.OutputStream |
getOutputStream(boolean append)
Returns an OuputStream to write the contents of this file, appending or overwriting the existing
contents. |
abstract java.lang.String |
getOwner()
Returns information about the owner of this file. |
abstract AbstractFile |
getParent()
Returns this file's parent, null if it doesn't have one. |
AbstractArchiveFile |
getParentArchive()
Convenience method that returns the parent AbstractArchiveFile that contains this file. |
AbstractFile |
getParentSilently()
Convience method that returns this file's parent, null if it doesn't have one or if it couldn't
be instanciated. |
abstract FilePermissions |
getPermissions()
Returns this file's permissions, as a FilePermissions object. |
java.lang.String |
getPermissionsString()
Returns a string representation of this file's permissions. |
abstract RandomAccessInputStream |
getRandomAccessInputStream()
Returns a RandomAccessInputStream to read the contents of this file with random access. |
abstract RandomAccessOutputStream |
getRandomAccessOutputStream()
Returns a RandomAccessOutputStream to write the contents of this file with random access. |
AbstractFile |
getRoot()
Returns the root folder that contains this file either as a direct or an indirect child. |
java.lang.String |
getSeparator()
Returns the path separator used by this file. |
abstract long |
getSize()
Returns this file's size in bytes, 0 if this file doesn't exist, -1 if the size is
undetermined. |
AbstractFile |
getTopAncestor()
Iterates through the ancestors returned by getAncestor() until the top-most ancestor is reached and
returns it. |
abstract long |
getTotalSpace()
Returns the total space (in bytes) of the disk/volume where this file is, -1 if this information is not available. |
abstract java.lang.Object |
getUnderlyingFileObject()
Returns the file Object of the underlying API providing access to the filesystem. |
FileURL |
getURL()
Returns the FileURL instance that represents this file's location. |
boolean |
hasAncestor()
Returns true if this AbstractFile has an ancestor, i.e. |
boolean |
hasAncestor(java.lang.Class abstractFileClass)
Returns true if this file is or has an ancestor (immediate or not) that is an instance of the given
Class or of a subclass of the Class. |
int |
hashCode()
|
abstract boolean |
hasRandomAccessInputStream()
Returns true if the underlying filesystem has support for random access input streams. |
abstract boolean |
hasRandomAccessOutputStream()
Returns true if the underlying filesystem has support for random access output streams. |
void |
importPermissions(AbstractFile sourceFile)
This method is a shorthand for importPermissions(AbstractFile, FilePermissions) called with
FilePermissions.DEFAULT_DIRECTORY_PERMISSIONS if this file is a directory or
FilePermissions.DEFAULT_FILE_PERMISSIONS if this file is a regular file. |
void |
importPermissions(AbstractFile sourceFile,
FilePermissions defaultPermissions)
Imports the given source file's permissions, overwriting this file's permissions. |
boolean |
isBrowsable()
Returns true if this file is browsable. |
abstract boolean |
isDirectory()
Returns true if this file is a directory, false in any of the following cases:
this file does not exist
this file is a regular file
this file is browsable (as reported by isBrowsable() but not a directory
|
boolean |
isHidden()
Returns true if this file is hidden. |
boolean |
isParentOf(AbstractFile file)
Returns true if this file is a parent folder of the given file, or if the two files are equal. |
boolean |
isRoot()
Returns true if this file is a root folder. |
abstract boolean |
isSymlink()
Returns true if this file is a symbolic link. |
abstract AbstractFile[] |
ls()
Returns the children files that this file contains. |
AbstractFile[] |
ls(FileFilter filter)
Returns the children files that this file contains, filtering out files that do not match the specified FileFilter. |
AbstractFile[] |
ls(FilenameFilter filter)
Returns the children files that this file contains, filtering out files that do not match the specified FilenameFilter. |
abstract void |
mkdir()
Creates this file as a directory. |
void |
mkdir(java.lang.String name)
Convenience method that creates a directory as a direct child of this directory. |
void |
mkdirs()
Creates this file as a directory and any parent directory that does not already exist. |
void |
mkfile()
Creates this file as an empty, non-directory file. |
void |
mkfile(java.lang.String name)
Convenience method that creates a file as a direct child of this directory. |
boolean |
moveTo(AbstractFile destFile)
Moves this file to a specified destination file, overwriting the destination if it exists. |
protected java.lang.String |
removeTrailingSeparator(java.lang.String path)
Tests if the given path contains a trailing separator, and if it does, removes it from the returned path. |
abstract AbstractProcess |
runProcess(java.lang.String[] tokens)
Creates a process executing the specified command tokens using this file as a working directory. |
abstract void |
setParent(AbstractFile parent)
Sets this file's parent. |
java.lang.String |
toString()
Returns a String representation of this file. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected FileURL fileURL
public static final java.lang.String DEFAULT_SEPARATOR
public static final int SHOULD_HINT
copyTo(AbstractFile)/moveTo(AbstractFile) *should* be used to copy/move the file (e.g. more efficient)
public static final int SHOULD_NOT_HINT
copyTo(AbstractFile)/moveTo(AbstractFile) *should not* be used to copy/move the file (default)
public static final int MUST_HINT
copyTo(AbstractFile)/moveTo(AbstractFile) *must* be used to copy/move the file (e.g. no other way to do so)
public static final int MUST_NOT_HINT
copyTo(AbstractFile)/moveTo(AbstractFile) *must not* be used to copy/move the file (e.g. not implemented)
public static final int IO_BUFFER_SIZE
protected static final java.util.regex.Pattern windowsDriveRootPattern
| Constructor Detail |
|---|
protected AbstractFile(FileURL url)
url - the FileURL instance that represents this file's location| Method Detail |
|---|
public FileURL getURL()
FileURL instance that represents this file's location.
public java.net.URL getJavaNetURL()
throws java.net.MalformedURLException
java.net.URL referring to the same location as the FileURL associated
with this AbstractFile.
The java.net.URL is created from the string representation of this file's FileURL.
Thus, any credentials this FileURL contains are preserved, but properties are lost.
The returned URL uses this AbstractFile to access the associated resource, via the
underlying URLConnection which delegates to this class.
It is important to note that this method is provided for interoperability purposes, for the sole purpose of
connecting to APIs that require a java.net.URL.
java.net.URL referring to the same location as this FileURL
java.net.MalformedURLException - if the java.net.URL could not parse the location of this FileURLpublic java.lang.String getName()
The returned name is the filename extracted from this file's FileURL
as returned by FileURL.getFilename(). If the filename is null (e.g. http://google.com), the
FileURL's host will be returned instead. If the host is null (e.g. smb://), an empty
String will be returned. Thus, the returned name will never be null.
This method should be overridden if a special processing (e.g. URL-decoding) needs to be applied to the returned filename.
public java.lang.String getExtension()
null if this file's name doesn't have an extension.
A filename has an extension if and only if:
- it contains at least one . character
- the last . is not the last character of the filename
- the last . is not the first character of the filename
null if this file's name doesn't have an extensionpublic java.lang.String getAbsolutePath()
The returned path will always be free of any login and password and thus can be safely displayed or stored.
public java.lang.String getCanonicalPath()
This implementation simply returns the value of getAbsolutePath(), and thus should be overridden
if canonical path resolution is available.
public AbstractFile getCanonicalFile()
AbstractFile representing the canonical path of this file, or this if the
absolute and canonical path of this file are identical.
AbstractFile representing the canonical path of this file, or this if the absolute and canonical
path of this file are identical.public java.lang.String getSeparator()
This default implementation returns the default separator "/", this method should be overridden if the path separator used by the file implementation is different.
public boolean isBrowsable()
true if this file is browsable. A file is considered browsable if it contains children files
that can be exposed by calling the ls() methods. AbstractArchiveFile implementations will
usually return true, as will directories (directories are always browsable).
public boolean isHidden()
true if this file is hidden.
This default implementation is solely based on the filename and returns true if this
file's name starts with '.'. This method should be overriden if the underlying filesystem has a notion
of hidden files.
public AbstractFile getRoot()
throws java.io.IOException
this is returned.
java.io.IOException - if the root file or one parent file could not be instanciatedpublic boolean isRoot()
true if this file is a root folder.
This default implementation characterizes root folders in the following way:
true if this file is a root folder
public java.io.InputStream getInputStream(long offset)
throws java.io.IOException
InputStream to read this file's contents, starting at the specified offset (in bytes).
A java.io.IOException is thrown if the file doesn't exist.
This method should be overridden whenever possible to provide a more efficient implementation as this
default implementation uses InputStream.skip(long) which, depending on the particular InputStream
implementation may just read bytes and discards them, which is very slow.
offset - the offset in bytes from the beginning of the file, must be >0
InputStream to read this file's contents, skipping the specified number of bytes
java.io.IOException - if this file cannot be read or is a folder.
public void copyStream(java.io.InputStream in,
boolean append)
throws FileTransferException
InputStream to this file. The provided InputStream
will *NOT* be closed by this method.
This method should be overridden by file protocols that do not offer a getOutputStream(boolean)
implementation, but that can take an InputStream and use it to write the file.
Read and write operations are buffered, with a buffer of IO_BUFFER_SIZE bytes. For performance
reasons, this buffer is provided by BufferPool. There is no need to provide a BufferedInputStream.
Copy progress can optionally be monitored by supplying a CounterInputStream.
in - the InputStream to read fromappend - if true, data written to the OutputStream will be appended to the end of this file. If false, any existing data will be overwritten.
FileTransferException - if something went wrong while reading from the InputStream or writing to this file
protected final void checkCopyPrerequisites(AbstractFile destFile,
boolean allowCaseVariations)
throws FileTransferException
FileTransferException in any of the following conditions are true, does nothing otherwise:
allowCaseVariations is true
and the destination filename is a case variation of the source
destFile - the destination file to copy this file toallowCaseVariations - if true and the destination file is a case variation of source, no exception will be thrown
FileTransferException - in any of the cases listed above, use FileTransferException.getReason() to
know the reason.
public boolean copyTo(AbstractFile destFile)
throws FileTransferException
This method returns true if the operation was successfully completed, false if the
operation could not be performed because of unsatisfied conditions (not an error).
A FileTransferException if the operation was attempted but failed for any of the following reasons:
This generic implementation will always attempt to copy files, thus either return true or
throw an exception, but will never return false. Symbolic links are skipped when encountered:
neither the link nor the linked file is copied. Also noteworthy is that no clean up is performed if an error
occurs in the midst of a transfer: files that have been copied (even partially) are left in the destination.
This method should be overridden by filesystems which are able to provide a more efficient implementation -- in particular, network-based filesystems that can perform a server-to-server copy.
destFile - the destination file to copy this file to
FileTransferException - in any of the cases listed above, use FileTransferException.getReason() to
know the reason.public int getCopyToHint(AbstractFile destFile)
copyTo(AbstractFile) method should be used to
copy this file to the specified destination file, rather than copying the file 'manually', using
copyStream(InputStream, boolean), or getInputStream() and getOutputStream(boolean).
Potential returned values are:
SHOULD_HINT if copyTo() should be preferred (more efficient)
SHOULD_NOT_HINT if the file should rather be copied using copyStream()
MUST_HINT if the file can only be copied using copyTo(), that's the case when getOutputStream() or copyStream() is not implemented
MUST_NOT_HINT if the file can only be copied using copyStream()
This default implementation returns SHOULD_NOT_HINT as some granularity is lost when using
copyTo() making it impossible to monitor progress when copying a file.
This method should be overridden when copyTo() should be favored over copyStream().
destFile - the destination file that is considered being copied
copyTo(AbstractFile) method should be used
public boolean moveTo(AbstractFile destFile)
throws FileTransferException
exists() will return false.
This method returns true if the operation was successfully completed, false if the
operation could not be performed because of unsatisfied conditions (not an error).
A FileTransferException if the operation was attempted but failed for any of the following reasons:
This generic implementation will always attempt to move files, thus either return true or
throw an exception, but will never return false.
Symbolic links are not moved to the destination when encountered: neither the link nor the linked file is moved,
and the symlink file is deleted.
This implementation first copies the file and it contents (if any) and then deletes it. Deletion occurs only after all files have been successfully copied. Also noteworthy is that no clean up is performed if an error occurs in the midst of a transfer: files that have been copied (even partially) are left in the destination.
This method should be overridden by filesystems which are able to provide a more efficient implementation -- in particular, network-based filesystems that can perform remote renaming.
destFile - the destination file to move this file to
FileTransferException - in any of the cases listed above, use FileTransferException.getReason() to
know the reason.public int getMoveToHint(AbstractFile destFile)
moveTo(AbstractFile) method should be used to
move this file to the specified destination file, rather than moving the file using
copyStream(InputStream, boolean) or getInputStream() and getOutputStream(boolean).
Potential returned values are:
SHOULD_HINT if copyTo() should be preferred (more efficient)
SHOULD_NOT_HINT if the file should rather be copied using copyStream()
MUST_HINT if the file can only be copied using copyTo(), that's the case when getOutputStream() or copyStream() is not implemented
MUST_NOT_HINT if the file can only be copied using copyStream()
This default implementation returns SHOULD_HINT if both this file and the specified destination file
use the same protocol and are located on the same host, SHOULD_NOT_HINT otherwise.
This method should be overridden to return SHOULD_NOT_HINT if the underlying file protocol doesn't not
allow direct move/renaming without copying the contents of the source (this) file.
destFile - the destination file that is considered being copied
moveTo(AbstractFile) method should be used
public void mkfile()
throws java.io.IOException
IOException)
if this file already exists. Note that this method may not always yield a zero-byte file (see below).
This generic implementation simply creates a zero-byte file. AbstractRWArchiveFile implementations
may want to override this method so that it creates a valid archive with no entry. To illustrate, an empty Zip
file with proper headers is 22-byte long.
java.io.IOException - if the file could not be created, either because it already exists or because of an I/O error
public AbstractFile[] ls(FileFilter filter)
throws java.io.IOException
isBrowsable() must return
true.
filter - the FileFilter to be used to filter files out from the list, may be null
java.io.IOException - if this operation is not possible (file is not browsable) or if an error occurred.
public AbstractFile[] ls(FilenameFilter filter)
throws java.io.IOException
isBrowsable() must return
true.
This default implementation filters out files *after* they have been created. This method should be overridden if a more efficient implementation can be provided by subclasses.
filter - the FilenameFilter to be used to filter out files from the list, may be null
java.io.IOException - if this operation is not possible (file is not browsable) or if an error occurred.public boolean changePermissions(int permissions)
true if
the operation was successful, false if at least one of the file permissions could not be changed.
The permissions int should be constructed using the permission types and accesses defined in
PermissionTypes and PermissionAccesses.
Implementation note: the default implementation of this method calls sequentially changePermission(int, int, boolean),
for each permission and access (that's a total 9 calls). This may affect performance on filesystems which need
to perform an I/O request to change each permission individually. In that case, and if the fileystem allows
to change all permissions at once, this method should be overridden.
permissions - new permissions for this file
public void importPermissions(AbstractFile sourceFile)
importPermissions(AbstractFile, FilePermissions) called with
FilePermissions.DEFAULT_DIRECTORY_PERMISSIONS if this file is a directory or
FilePermissions.DEFAULT_FILE_PERMISSIONS if this file is a regular file.
sourceFile - the file from which to import permissions
public void importPermissions(AbstractFile sourceFile,
FilePermissions defaultPermissions)
SimpleFilePermissions.padPermissions(FilePermissions, FilePermissions) for more information about
permissions padding.
sourceFile - the file from which to import permissionsdefaultPermissions - default permissions to useSimpleFilePermissions.padPermissions(FilePermissions, FilePermissions)public java.lang.String getPermissionsString()
The first character is 'l' if this file is a symbolic link,'d' if it is a directory, '-' otherwise. Then the string contains up to 3 character triplets, for each of the 'user', 'group' and 'other' access types, each containing the following characters:
The first character triplet for 'user' access will always be added to the permissions. Then the 'group' and 'other' triplets will only be added if at least one of the user permission bits is supported, as tested with this file's permissions mask. Here are a couple examples to illustrate:
d---, no matter
what permission values the FilePermissions returned by getPermissions() contains-rwxrwxrwx
public void deleteRecursively()
throws java.io.IOException
java.io.IOException - if an error occurred while deleting a file or listing a directory's contentspublic final java.lang.String getNameWithoutExtension()
A filename has an extension if and only if:
- it contains at least one . character
- the last . is not the last character of the filename
- the last . is not the first character of the filename
If this file has no extension, its full name is returned.
getName(),
getExtension()public final java.lang.String getAbsolutePath(boolean appendSeparator)
true is passed.
appendSeparator - if true, a separator will be appended to the returned path
public final java.lang.String getCanonicalPath(boolean appendSeparator)
true is passed.
appendSeparator - if true, a separator will be appended to the returned path
public final AbstractFile getChild(java.lang.String relativePath)
throws java.io.IOException
IOException may be thrown if the child file could not be instanciated but the returned file
instance should never be null.
relativePath - the child's path, relative to this file's path
java.io.IOException - if the child file could not be instanciated
public final AbstractFile getDirectChild(java.lang.String filename)
throws java.io.IOException
IOException will be thrown in any of the following cases:
null.
Although getChild(java.lang.String) can be used to retrieve a direct child file, this method should be favored because
it allows to use this file instance as the parent of the returned child file.
filename - the name of the child file to be created
java.io.IOException - in any of the cases listed abovepublic final AbstractFile getParentSilently()
null if it doesn't have one or if it couldn't
be instanciated. This method is less granular than getParent() but is convenient in cases where no
distinction is made between having no parent and not being able to instanciate it.
null if it doesn't have one or if it couldn't be instanciated
public final void mkdir(java.lang.String name)
throws java.io.IOException
name - name of the directory to create
java.io.IOException - if the directory could not be created, either because the file already exists or for any
other reason.
public final void mkdirs()
throws java.io.IOException
IOException) if this file already exists. It may also fail because of an I/O error ;
in this case, this method will not remove the parent directories it has created (if any).
java.io.IOException - if this file already exists or if an I/O error occurred.
public final void mkfile(java.lang.String name)
throws java.io.IOException
name - name of the file to create
java.io.IOException - if the file could not be created, either because the file already exists or for any
other reason.public final AbstractFile getAncestor()
AbstractFile if it has one, this otherwise:
ProxyFile, returns the return value of ProxyFile.getProxiedFile()
ProxyFile, returns this
AbstractFile if it has one, this otherwisepublic final AbstractFile getAncestor(java.lang.Class abstractFileClass)
this if this instance's class matches those criteria. Returns null if this
file has no such ancestor.
Note that the specified must correspond to an AbstractFile subclass. Specifying any other Class will
always yield to this method returning null. Also note that this method will always return
this if AbstractFile.class is specified.
abstractFileClass - a Class corresponding to an AbstractFile subclass
this if this instance's class matches those criteria. Returns null if this
file has no such ancestor.public final AbstractFile getTopAncestor()
getAncestor() until the top-most ancestor is reached and
returns it. If this file has no ancestor, this will be returned.
this if this file has no ancestorpublic final boolean hasAncestor()
true if this AbstractFile has an ancestor, i.e. if this file is a
ProxyFile, false otherwise.
true if this AbstractFile has an ancestor, false otherwise.public final boolean hasAncestor(java.lang.Class abstractFileClass)
true if this file is or has an ancestor (immediate or not) that is an instance of the given
Class or of a subclass of the Class. Note that the specified must correspond to an
AbstractFile subclass. Specifying any other Class will always yield to this method returning
false. Also note that this method will always return true if
AbstractFile.class is specified.
abstractFileClass - a Class corresponding to an AbstractFile subclass
true if this file has an ancestor (immediate or not) that is an instance of the given Class
or of a subclass of the given Class.public final boolean isParentOf(AbstractFile file)
true if this file is a parent folder of the given file, or if the two files are equal.
file - the AbstractFile to test
public final AbstractArchiveFile getParentArchive()
AbstractArchiveFile that contains this file. If this file
is an AbstractArchiveFile or an ancestor of AbstractArchiveFile, this is returned. If this file
is not contained by an archive or is not an archive, null is returned.
public final javax.swing.Icon getIcon(java.awt.Dimension preferredResolution)
FileIconProvider
registered in FileFactory. The specified preferred resolution will be used as a hint, but the returned
icon may have different dimension; see FileIconProvider.getFileIcon(AbstractFile, java.awt.Dimension)
for full details.
This method may return null if the JVM is running on a headless environment.
preferredResolution - the preferred icon resolution
null if the JVM is running on a headless environmentFileFactory.getDefaultFileIconProvider(),
FileIconProvider.getFileIcon(AbstractFile, java.awt.Dimension)public final javax.swing.Icon getIcon()
FileIconProvider
registered in FileFactory. The default preferred resolution for the icon is 16x16 pixels.
This method may return null if the JVM is running on a headless environment.
null if the JVM is running on a headless environmentFileFactory.getDefaultFileIconProvider(),
FileIconProvider.getFileIcon(AbstractFile, java.awt.Dimension)
public final java.lang.String calculateChecksum(java.lang.String algorithm)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
MessageDigest, until EOF is reached.
The checksum is returned as an hexadecimal string, such as "6d75636f0a". The length of this string depends on the kind of algorithm.
Note: this method does not reset the MessageDigest after the checksum has been calculated.
algorithm - the algorithm to use for calculating the checksum
java.io.IOException - if an I/O error occurred while calculating the checksum
java.security.NoSuchAlgorithmException - if the specified algorithm does not correspond to any MessageDigest registered
with the Java Cryptography Extension.
public final java.lang.String calculateChecksum(java.security.MessageDigest messageDigest)
throws java.io.IOException
MessageDigest, until EOF is reached.
The checksum is returned as an hexadecimal string, such as "6d75636f0a". The length of this string depends on
the kind of MessageDigest.
Note: this method does not reset the MessageDigest after the checksum has been calculated.
messageDigest - the MessageDigest to use for calculating the checksum
java.io.IOException - if an I/O error occurred while calculating the checksumprotected final java.lang.String addTrailingSeparator(java.lang.String path)
getSeparator().
path - the path for which to add a trailing separator
protected final java.lang.String removeTrailingSeparator(java.lang.String path)
getSeparator().
path - the path for which to remove the trailing separator
protected final void copyRecursively(AbstractFile sourceFile,
AbstractFile destFile)
throws FileTransferException
sourceFile - the file to copydestFile - the destination file
FileTransferException - if an error occurred while copying the file
protected final void deleteRecursively(AbstractFile file)
throws java.io.IOException
file - the file to delete
java.io.IOException - if an error occurred while deleting a file or listing a directory's contentspublic final boolean changePermissions(FilePermissions permissions)
changePermissions(int) with the given permissions' int value.
permissions - new permissions for this file
public static java.lang.String getExtension(java.lang.String filename)
null if the filename doesn't have an extension.
A filename has an extension if and only if:
- it contains at least one . character
- the last . is not the last character of the filename
- the last . is not the first character of the filename
filename - a filename, not a full path
null if the filename doesn't have an extension
public static java.lang.String calculateChecksum(java.io.InputStream in,
java.security.MessageDigest messageDigest)
throws java.io.IOException
InputStream
calculated by reading the stream and feeding the bytes to the given MessageDigest until EOF is
reached.
Important: this method does not close the InputStream, and does n