Package patterntesting.runtime.io
Class ExtendedFile
- java.lang.Object
-
- java.io.File
-
- patterntesting.runtime.io.ExtendedFile
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<java.io.File>
public final class ExtendedFile extends java.io.File
This is the extended version of theFile
class. It provides some additional methods which are missing in this class.- Since:
- 1.5 (27.08.2014)
- Author:
- oliver
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ExtendedFile(java.io.File file)
Instantiates a new extended file.ExtendedFile(java.io.File parent, java.io.File file)
Instantiates a new extended file.ExtendedFile(java.io.File parent, java.lang.String filename)
Instantiates a new extended file.ExtendedFile(java.lang.String filename)
Instantiates a new extended file.ExtendedFile(java.lang.String parent, java.lang.String filename)
Instantiates a new extended file.ExtendedFile(java.net.URI fileURI)
Instantiates a new extended file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.OutputStream
createOutputStream()
Creates the output stream of the file.static java.io.OutputStream
createOutputStreamFor(java.io.File file)
Creates the output stream of the file.static java.io.File
createTmpdir(java.lang.String prefix, java.lang.String suffix)
Creates a directory in the temp directory.boolean
endsWith(java.io.File extension)
With this method you can ask if a file ends with the given extension.boolean
equals(java.lang.Object obj)
Comparing two files is not so easy as it seems to be.java.io.File
getBaseDir(java.io.File extension)
Returns the base of the given file.ExtendedFile
getParentExtendedFile()
Gets the parent asExtendedFile
.static java.io.File
getTmpdir(java.lang.String filename)
Gets the tmpdir.int
hashCode()
Hash code.java.io.File
normalize()
Normalizes a file, analogous toFilenameUtils.normalize(String)
.static java.io.File
normalize(java.io.File file)
Normalizes a file, analogous toFilenameUtils.normalize(String)
.static java.lang.String[]
toStringArray(java.util.List<java.io.File> files)
Converts a list with files into a string array.static void
validate(java.io.File file)
Validates the given file and throws anFileNotFoundException
if it is not a valid file.-
Methods inherited from class java.io.File
canExecute, canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getFreeSpace, getName, getParent, getParentFile, getPath, getTotalSpace, getUsableSpace, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toPath, toString, toURI, toURL
-
-
-
-
Constructor Detail
-
ExtendedFile
public ExtendedFile(java.io.File file)
Instantiates a new extended file.- Parameters:
file
- the file
-
ExtendedFile
public ExtendedFile(java.lang.String filename)
Instantiates a new extended file.- Parameters:
filename
- the filename
-
ExtendedFile
public ExtendedFile(java.io.File parent, java.lang.String filename)
Instantiates a new extended file.- Parameters:
parent
- the parentfilename
- the filename
-
ExtendedFile
public ExtendedFile(java.lang.String parent, java.lang.String filename)
Instantiates a new extended file.- Parameters:
parent
- the parentfilename
- the filename
-
ExtendedFile
public ExtendedFile(java.net.URI fileURI)
Instantiates a new extended file.- Parameters:
fileURI
- the file uri
-
ExtendedFile
public ExtendedFile(java.io.File parent, java.io.File file)
Instantiates a new extended file.- Parameters:
parent
- the parentfile
- the file
-
-
Method Detail
-
validate
public static void validate(java.io.File file) throws java.io.FileNotFoundException
Validates the given file and throws anFileNotFoundException
if it is not a valid file. This is the case if- the file does not exist or
- the file exists, but is not a file but a directory.
If the file does not exist it tr tries guess the real filename. E.g. one of the common platform problems is that Windows does not support case sensitive filenames whereas Unix platforms distinguish between upper/lowercase in filenames. "readme.txt" and "README.TXT" are two different files under Unix but not on Windows.
- Parameters:
file
- the file- Throws:
java.io.FileNotFoundException
- the file not found exception- Since:
- 1.7
-
createTmpdir
public static java.io.File createTmpdir(java.lang.String prefix, java.lang.String suffix) throws java.io.IOException
Creates a directory in the temp directory.- Parameters:
prefix
- the prefixsuffix
- the suffix- Returns:
- the directory
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
getTmpdir
public static java.io.File getTmpdir(java.lang.String filename)
Gets the tmpdir.- Parameters:
filename
- the filename- Returns:
- the tmpdir
-
toStringArray
public static java.lang.String[] toStringArray(java.util.List<java.io.File> files)
Converts a list with files into a string array.Since 1.7 this method was moved from the (now deprecated) FileHelper to this class here.
- Parameters:
files
- the files- Returns:
- the string[]
- Since:
- 1.5 (27.08.2014)
-
getParentExtendedFile
public ExtendedFile getParentExtendedFile()
Gets the parent asExtendedFile
. This method was introduced becauseFile.getParent()
andFile.getParentFile()
also exists.- Returns:
- the parent extended file
-
normalize
public java.io.File normalize()
Normalizes a file, analogous toFilenameUtils.normalize(String)
. But before we normalize it we try to ask to OS for the canonical path for it.- Returns:
- the normalized file
-
normalize
public static java.io.File normalize(java.io.File file)
Normalizes a file, analogous toFilenameUtils.normalize(String)
. But before we normalize it we try to ask to OS for the canonical path for it.- Parameters:
file
- the file- Returns:
- the file
-
endsWith
public boolean endsWith(java.io.File extension)
With this method you can ask if a file ends with the given extension.- Parameters:
extension
- the extension - must be a relative path e.g. "WEB-INF/classes"- Returns:
- true, if successful
-
getBaseDir
public java.io.File getBaseDir(java.io.File extension)
Returns the base of the given file. The 'base' is the given file without the extension. Remember, the extension parameter is of typeFile
, so it must be a file (not a file extension like ".txt").- Parameters:
extension
- the extension - must be a relative path e.g. "WEB-INF/classes"- Returns:
- the file, e.g. "/tmp/web"
-
createOutputStreamFor
public static java.io.OutputStream createOutputStreamFor(java.io.File file)
Creates the output stream of the file. As fallback stdout will be used if the output stream cannot be created.- Parameters:
file
- the file- Returns:
- the output stream
- Since:
- 1.7
-
createOutputStream
public java.io.OutputStream createOutputStream()
Creates the output stream of the file. As fallback stdout will be used if the output stream cannot be created.- Returns:
- the output stream
- Since:
- 1.7
-
equals
public boolean equals(java.lang.Object obj)
Comparing two files is not so easy as it seems to be. On unix systems or Mac OS-X you can see the same file via two different mount points or as two different hard links. If you are on *nix you can use the inode to compare but how to get the inode?- Overrides:
equals
in classjava.io.File
- Parameters:
obj
- the other file- Returns:
- true, if successful
- See Also:
File.equals(java.lang.Object)
-
hashCode
public int hashCode()
Hash code.- Overrides:
hashCode
in classjava.io.File
- Returns:
- the int
- See Also:
File.hashCode()
-
-