Class PlaceholderFile
- java.lang.Object
-
- java.io.File
-
- adams.core.io.PlaceholderFile
-
- All Implemented Interfaces:
Serializable,Comparable<File>
- Direct Known Subclasses:
FlowFile,PlaceholderDirectory,WekaExperimentFile
public class PlaceholderFile extends File
A specialized File class makes use of system-wide defined placeholders.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
Placeholders, Serialized Form
-
-
Field Summary
-
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
-
-
Constructor Summary
Constructors Constructor Description PlaceholderFile()Creates a newPlaceholderFileinstance by using the given file.PlaceholderFile(File file)Creates a newPlaceholderFileinstance by using the given file.PlaceholderFile(File parent, String child)Creates a newFileinstance from a parent abstract pathname and a child pathname string.PlaceholderFile(String pathname)Creates a newFileinstance by converting the given pathname string into an abstract pathname.PlaceholderFile(String parent, String child)Creates a newFileinstance from a parent pathname string and a child pathname string.PlaceholderFile(URI uri)Creates a new File instance by converting the given file: URI into an abstract pathname.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanExecute()Tests whether the application can execute the file denoted by this abstract pathname.booleancanRead()Tests whether the application can read the file denoted by this abstract pathname.booleancanWrite()Tests whether the application can modify the file denoted by this abstract pathname.PlaceholderFilechangeExtension(String newExt)Swaps the current extension with the new one.PlaceholderFilechangeExtension(String oldExt, String newExt)Swaps the specified old extension with the new one.intcompareTo(File pathname)Compares two abstract pathnames lexicographically.booleancreateNewFile()Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.booleandelete()Deletes the file or directory denoted by this abstract pathname.voiddeleteOnExit()Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates.booleanexists()Tests whether the file or directory denoted by this abstract pathname exists.protected Stringexpand(String path)Expands any placeholders, if necessary.protected static StringfixSeparator(File file)Fixes the separator in the given file, changing backslashes to forward slashes under Linux and vice versa under Windows.protected static StringfixSeparator(String path)Fixes the separator in the given string, changing backslashes to forward slashes under Linux and vice versa under Windows.StringgetAbsolutePath()Returns the absolute pathname string of this abstract pathname.StringgetCanonicalPath()Returns the canonical pathname string of this abstract pathname.StringgetExtension()Returns the extension, i.e., the string after the last dot.StringgetExtension(String suffix)Returns the extension, i.e., the string after the last dot.longgetFreeSpace()Returns the number of unallocated bytes in the partition named by this abstract path name.StringgetParent()Returns the pathname string of this abstract pathname's parent, ornullif this pathname does not name a parent directory.FilegetParentFile()Returns the abstract pathname of this abstract pathname's parent, ornullif this pathname does not name a parent directory.longgetTotalSpace()Returns the size of the partition named by this abstract pathname.longgetUsableSpace()Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname.booleanisAbsolute()Tests whether this abstract pathname is absolute.booleanisDirectory()Tests whether the file denoted by this abstract pathname is a directory.booleanisFile()Tests whether the file denoted by this abstract pathname is a normal file.booleanisHidden()Tests whether the file named by this abstract pathname is a hidden file.static booleanisValid(PlaceholderFile file)Checks whether the placeholer file is valid.static booleanisValid(String file)Checks whether the placeholer file is valid.longlastModified()Returns the time that the file denoted by this abstract pathname was last modified.longlength()Returns the length of the file denoted by this abstract pathname.String[]list()Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.String[]list(String regExp)Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname, as long as they match the regular expression.PlaceholderFile[]listFiles()Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.PlaceholderFile[]listFiles(FileFilter filter)Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.PlaceholderFile[]listFiles(FilenameFilter filter)Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.booleanmkdir()Creates the directory named by this abstract pathname.booleanrenameTo(File dest)Renames the file denoted by this abstract pathname.booleansetExecutable(boolean executable, boolean ownerOnly)Sets the owner's or everybody's execute permission for this abstract pathname.booleansetLastModified(long time)Sets the last-modified time of the file or directory named by this abstract pathname.booleansetReadable(boolean readable, boolean ownerOnly)Sets the owner's or everybody's read permission for this abstract pathname.booleansetReadOnly()Marks the file or directory named by this abstract pathname so that only read operations are allowed.booleansetWritable(boolean writable, boolean ownerOnly)Sets the owner's or everybody's write permission for this abstract pathname.PathtoPath()Turns the file object into aPathobject.protected PlaceholderFile[]toPlaceholderFiles(File[] files)Turns the regularFileobjects intoPlaceholderFileones.-
Methods inherited from class java.io.File
createTempFile, createTempFile, equals, getAbsoluteFile, getCanonicalFile, getName, getPath, hashCode, list, listRoots, mkdirs, setExecutable, setReadable, setWritable, toString, toURI, toURL
-
-
-
-
Constructor Detail
-
PlaceholderFile
public PlaceholderFile()
Creates a newPlaceholderFileinstance by using the given file.
-
PlaceholderFile
public PlaceholderFile(File file)
Creates a newPlaceholderFileinstance by using the given file.- Parameters:
file- the file to use
-
PlaceholderFile
public PlaceholderFile(String pathname)
Creates a newFileinstance by converting the given pathname string into an abstract pathname. If the given string is the empty string, then the result is the empty abstract pathname.- Parameters:
pathname- A pathname string
-
PlaceholderFile
public PlaceholderFile(String parent, String child)
Creates a newFileinstance from a parent pathname string and a child pathname string.If
parentisnullthen the newFileinstance is created as if by invoking the single-argumentFileconstructor on the givenchildpathname string.Otherwise the
parentpathname string is taken to denote a directory, and thechildpathname string is taken to denote either a directory or a file. If thechildpathname string is absolute then it is converted into a relative pathname in a system-dependent way. Ifparentis the empty string then the newFileinstance is created by convertingchildinto an abstract pathname and resolving the result against a system-dependent default directory. Otherwise each pathname string is converted into an abstract pathname and the child abstract pathname is resolved against the parent.- Parameters:
parent- The parent pathname stringchild- The child pathname string
-
PlaceholderFile
public PlaceholderFile(File parent, String child)
Creates a newFileinstance from a parent abstract pathname and a child pathname string.If
parentisnullthen the newFileinstance is created as if by invoking the single-argumentFileconstructor on the givenchildpathname string.Otherwise the
parentabstract pathname is taken to denote a directory, and thechildpathname string is taken to denote either a directory or a file. If thechildpathname string is absolute then it is converted into a relative pathname in a system-dependent way. Ifparentis the empty abstract pathname then the newFileinstance is created by convertingchildinto an abstract pathname and resolving the result against a system-dependent default directory. Otherwise each pathname string is converted into an abstract pathname and the child abstract pathname is resolved against the parent.- Parameters:
parent- The parent abstract pathnamechild- The child pathname string
-
PlaceholderFile
public PlaceholderFile(URI uri)
Creates a new File instance by converting the given file: URI into an abstract pathname.The exact form of a file: URI is system-dependent, hence the transformation performed by this constructor is also system-dependent.
For a given abstract pathname f it is guaranteed that
new File( f.
so long as the original abstract pathname, the URI, and the new abstract pathname are all created in (possibly different invocations of) the same Java virtual machine. This relationship typically does not hold, however, when a file: URI that is created in a virtual machine on one operating system is converted into an abstract pathname in a virtual machine on a different operating system.toURI()).equals( f.getAbsoluteFile())- Parameters:
uri- An absolute, hierarchical URI with a scheme equal to "file", a non-empty path component, and undefined authority, query, and fragment components
-
-
Method Detail
-
canExecute
public boolean canExecute()
Tests whether the application can execute the file denoted by this abstract pathname.- Overrides:
canExecutein classFile- Returns:
trueif and only if the abstract pathname exists and the application is allowed to execute the file
-
canRead
public boolean canRead()
Tests whether the application can read the file denoted by this abstract pathname.
-
canWrite
public boolean canWrite()
Tests whether the application can modify the file denoted by this abstract pathname.
-
compareTo
public int compareTo(File pathname)
Compares two abstract pathnames lexicographically. The ordering defined by this method depends upon the underlying system. On UNIX systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows systems it is not.- Specified by:
compareToin interfaceComparable<File>- Overrides:
compareToin classFile- Parameters:
pathname- The abstract pathname to be compared to this abstract pathname- Returns:
- Zero if the argument is equal to this abstract pathname, a value less than zero if this abstract pathname is lexicographically less than the argument, or a value greater than zero if this abstract pathname is lexicographically greater than the argument
-
createNewFile
public boolean createNewFile() throws IOExceptionAtomically 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
FileLockfacility should be used instead.- Overrides:
createNewFilein classFile- Returns:
trueif the named file does not exist and was successfully created;falseif the named file already exists- Throws:
IOException- If an I/O error occurred
-
delete
public boolean 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.
-
deleteOnExit
public void deleteOnExit()
Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates. Files (or directories) are deleted in the reverse order that they are registered. Invoking this method to delete a file or directory that is already registered for deletion has no effect. Deletion will be attempted only for normal termination of the virtual machine, as defined by the Java Language Specification.Once deletion has been requested, it is not possible to cancel the request. This method should therefore be used with care.
Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The
FileLockfacility should be used instead.- Overrides:
deleteOnExitin classFile
-
exists
public boolean exists()
Tests whether the file or directory denoted by this abstract pathname exists.
-
getCanonicalPath
public String getCanonicalPath() throws IOException
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.
- Overrides:
getCanonicalPathin classFile- Returns:
- The canonical pathname string denoting the same file or directory as this abstract pathname
- Throws:
IOException- If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries
-
getFreeSpace
public long getFreeSpace()
Returns the number of unallocated bytes in the partition named by this abstract path name.The returned number of unallocated bytes is a hint, but not a guarantee, that it is possible to use most or any of these bytes. The number of unallocated bytes is most likely to be accurate immediately after this call. It is likely to be made inaccurate by any external I/O operations including those made on the system outside of this virtual machine. This method makes no guarantee that write operations to this file system will succeed.
- Overrides:
getFreeSpacein classFile- Returns:
- The number of unallocated bytes on the partition 0L
if the abstract pathname does not name a partition. This
value will be less than or equal to the total file system size
returned by
getTotalSpace().
-
getTotalSpace
public long getTotalSpace()
Returns the size of the partition named by this abstract pathname.- Overrides:
getTotalSpacein classFile- Returns:
- The size, in bytes, of the partition or 0L if this abstract pathname does not name a partition
-
getUsableSpace
public long getUsableSpace()
Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname. When possible, this method checks for write permissions and other operating system restrictions and will therefore usually provide a more accurate estimate of how much new data can actually be written thangetFreeSpace().The returned number of available bytes is a hint, but not a guarantee, that it is possible to use most or any of these bytes. The number of unallocated bytes is most likely to be accurate immediately after this call. It is likely to be made inaccurate by any external I/O operations including those made on the system outside of this virtual machine. This method makes no guarantee that write operations to this file system will succeed.
- Overrides:
getUsableSpacein classFile- Returns:
- The number of available bytes on the partition or 0L
if the abstract pathname does not name a partition. On
systems where this information is not available, this method
will be equivalent to a call to
getFreeSpace().
-
isAbsolute
public boolean isAbsolute()
Tests whether this abstract pathname is absolute. The definition of absolute pathname is system dependent. On UNIX systems, a pathname is absolute if its prefix is"/". On Microsoft Windows systems, a pathname is absolute if its prefix is a drive specifier followed by"\\", or if its prefix is"\\\\".- Overrides:
isAbsolutein classFile- Returns:
trueif this abstract pathname is absolute,falseotherwise
-
isDirectory
public boolean isDirectory()
Tests whether the file denoted by this abstract pathname is a directory.- Overrides:
isDirectoryin classFile- Returns:
trueif and only if the file denoted by this abstract pathname exists and is a directory;falseotherwise
-
isFile
public boolean 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.
-
isHidden
public boolean 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.
-
lastModified
public long lastModified()
Returns the time that the file denoted by this abstract pathname was last modified.- Overrides:
lastModifiedin classFile- Returns:
- A
longvalue representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or0Lif the file does not exist or if an I/O error occurs
-
length
public long length()
Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.
-
list
public String[] 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.
-
list
public String[] list(String regExp)
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname, as long as they match the regular expression.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.
- Parameters:
regExp- The regular expression that the filenames must match.- Returns:
- 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
nullif this abstract pathname does not denote a directory, or if an I/O error occurs.
-
toPlaceholderFiles
protected PlaceholderFile[] toPlaceholderFiles(File[] files)
Turns the regularFileobjects intoPlaceholderFileones.- Parameters:
files- the files to convert- Returns:
- the converted files
-
listFiles
public PlaceholderFile[] 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 ofFileobjects 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 theconstructor. 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.File(File, String)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.
- Overrides:
listFilesin classFile- Returns:
- 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
nullif this abstract pathname does not denote a directory, or if an I/O error occurs.
-
listFiles
public PlaceholderFile[] listFiles(FilenameFilter filter)
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 themethod, except that the pathnames in the returned array must satisfy the filter. If the givenlistFiles()filterisnullthen all pathnames are accepted. Otherwise, a pathname satisfies the filter if and only if the valuetrueresults when themethod of the filter is invoked on this abstract pathname and the name of a file or directory in the directory that it denotes.FilenameFilter.accept(java.io.File, java.lang.String)- Overrides:
listFilesin classFile- Parameters:
filter- A filename filter- Returns:
- 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
nullif this abstract pathname does not denote a directory, or if an I/O error occurs. - Throws:
SecurityException- If a security manager exists and itsmethod denies read access to the directorySecurityManager.checkRead(java.lang.String)- Since:
- 1.2
-
listFiles
public PlaceholderFile[] listFiles(FileFilter filter)
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 themethod, except that the pathnames in the returned array must satisfy the filter. If the givenlistFiles()filterisnullthen all pathnames are accepted. Otherwise, a pathname satisfies the filter if and only if the valuetrueresults when themethod of the filter is invoked on the pathname.FileFilter.accept(java.io.File)- Overrides:
listFilesin classFile- Parameters:
filter- A file filter- Returns:
- 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
nullif this abstract pathname does not denote a directory, or if an I/O error occurs. - Throws:
SecurityException- If a security manager exists and itsmethod denies read access to the directorySecurityManager.checkRead(java.lang.String)- Since:
- 1.2
-
mkdir
public boolean mkdir()
Creates the directory named by this abstract pathname.
-
renameTo
public boolean renameTo(File dest)
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.
-
setExecutable
public boolean setExecutable(boolean executable, boolean ownerOnly)Sets the owner's or everybody's execute permission for this abstract pathname.- Overrides:
setExecutablein classFile- Parameters:
executable- Iftrue, sets the access permission to allow execute operations; iffalseto disallow execute operationsownerOnly- Iftrue, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's execute permission from that of others, then the permission will apply to everybody, regardless of this value.- Returns:
trueif and only if the operation succeeded. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. Ifexecutableisfalseand the underlying file system does not implement an execute permission, then the operation will fail.
-
setLastModified
public boolean setLastModified(long time)
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
method will return the (possibly truncated)lastModified()timeargument that was passed to this method.- Overrides:
setLastModifiedin classFile- Parameters:
time- The new last-modified time, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)- Returns:
trueif and only if the operation succeeded;falseotherwise
-
setReadable
public boolean setReadable(boolean readable, boolean ownerOnly)Sets the owner's or everybody's read permission for this abstract pathname.- Overrides:
setReadablein classFile- Parameters:
readable- Iftrue, sets the access permission to allow read operations; iffalseto disallow read operationsownerOnly- Iftrue, the read permission applies only to the owner's read permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's read permission from that of others, then the permission will apply to everybody, regardless of this value.- Returns:
trueif and only if the operation succeeded. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. Ifreadableisfalseand the underlying file system does not implement a read permission, then the operation will fail.
-
setReadOnly
public boolean 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 is guaranteed not to change until it is either deleted or marked to allow write access. Whether or not a read-only file or directory may be deleted depends upon the underlying system.- Overrides:
setReadOnlyin classFile- Returns:
trueif and only if the operation succeeded;falseotherwise
-
setWritable
public boolean setWritable(boolean writable, boolean ownerOnly)Sets the owner's or everybody's write permission for this abstract pathname.- Overrides:
setWritablein classFile- Parameters:
writable- Iftrue, sets the access permission to allow write operations; iffalseto disallow write operationsownerOnly- Iftrue, the write permission applies only to the owner's write permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's write permission from that of others, then the permission will apply to everybody, regardless of this value.- Returns:
trueif and only if the operation succeeded. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname.
-
getParent
public String getParent()
Returns the pathname string of this abstract pathname's parent, ornullif 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.
-
getParentFile
public File getParentFile()
Returns the abstract pathname of this abstract pathname's parent, ornullif 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.
- Overrides:
getParentFilein classFile- Returns:
- The abstract pathname of the parent directory named by this
abstract pathname, or
nullif this pathname does not name a parent - Since:
- 1.2
-
expand
protected String expand(String path)
Expands any placeholders, if necessary.- Parameters:
path- the path to expand (if necessary)- Returns:
- the expanded path
-
getAbsolutePath
public String getAbsolutePath()
Returns the absolute pathname string of this abstract pathname. This also replaces existing placeholders with the actual values.- Overrides:
getAbsolutePathin classFile- Returns:
- The absolute pathname string denoting the same file or directory as this abstract pathname
-
fixSeparator
protected static String fixSeparator(File file)
Fixes the separator in the given file, changing backslashes to forward slashes under Linux and vice versa under Windows.- Parameters:
file- the path to process- Returns:
- the fixed path
-
fixSeparator
protected static String fixSeparator(String path)
Fixes the separator in the given string, changing backslashes to forward slashes under Linux and vice versa under Windows.- Parameters:
path- the path to process- Returns:
- the fixed path
-
isValid
public static boolean isValid(String file)
Checks whether the placeholer file is valid.- Parameters:
file- the file to check- Returns:
- true if valid
-
isValid
public static boolean isValid(PlaceholderFile file)
Checks whether the placeholer file is valid.- Parameters:
file- the file to check- Returns:
- true if valid
-
getExtension
public String getExtension()
Returns the extension, i.e., the string after the last dot. If extension is from a compressed file, like "file.tar.gz", this will return only "gz".- Returns:
- the extension (without the dot), empty string if not available
- See Also:
getExtension(String)
-
getExtension
public String getExtension(String suffix)
Returns the extension, i.e., the string after the last dot. Skips the suffix (for instance for compressed files, this could be ".gz" or "gz") before locating the next ".".- Parameters:
suffix- the suffix to skip. with or without preceding dot, as it gets automatically prepended if missing- Returns:
- the extension (without the dot), empty string if not available
-
changeExtension
public PlaceholderFile changeExtension(String newExt)
Swaps the current extension with the new one. UsesgetExtension()to determine the old extension.- Parameters:
newExt- the new extension to use- Returns:
- the file with the new extension
- See Also:
changeExtension(String, String)
-
changeExtension
public PlaceholderFile changeExtension(String oldExt, String newExt)
Swaps the specified old extension with the new one.- Parameters:
oldExt- the old extension to replacenewExt- the new extension to use- Returns:
- the file with the new extension
-
-