Class ExtendedFile
java.lang.Object
java.io.File
clazzfish.monitor.io.ExtendedFile
- All Implemented Interfaces:
Serializable
,Comparable<File>
This is the extended version of the
File
class. It provides some
additional methods which are missing in this class.
Originally this class was part of the PatternTesting project but is now transfered to here.
- Author:
- oliver
- See Also:
-
Field Summary
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
-
Constructor Summary
ConstructorsConstructorDescriptionExtendedFile
(File file) Instantiates a new extended file.ExtendedFile
(File parent, File file) Instantiates a new extended file.ExtendedFile
(File parent, String filename) Instantiates a new extended file.ExtendedFile
(String filename) Instantiates a new extended file.ExtendedFile
(String parent, String filename) Instantiates a new extended file.ExtendedFile
(URI fileURI) Instantiates a new extended file. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Creates the given directory if it does not exist.Creates the output stream of the file.static OutputStream
createOutputStreamFor
(File file) Creates the output stream of the file.static File
createTmpdir
(String prefix, String suffix) Creates a directory in the temp directory.boolean
With this method you can ask if a file ends with the given extension.boolean
Comparing two files is not so easy as it seems to be.getBaseDir
(File extension) Returns the base of the given file.Gets the parent asExtendedFile
.static File
Gets the tmpdir.int
hashCode()
Hash code.Normalizes a file, analogous toFilenameUtils.normalize(String)
.static File
Normalizes a file, analogous toFilenameUtils.normalize(String)
.static String[]
toStringArray
(List<File> files) Converts a list with files into a string array.static void
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 Details
-
ExtendedFile
Instantiates a new extended file.- Parameters:
file
- the wrapped file
-
ExtendedFile
Instantiates a new extended file.- Parameters:
filename
- the filename
-
ExtendedFile
-
ExtendedFile
-
ExtendedFile
Instantiates a new extended file.- Parameters:
fileURI
- the file uri
-
ExtendedFile
-
-
Method Details
-
validate
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:
FileNotFoundException
- the file not found exception- Since:
- 1.7
-
createDir
Creates the given directory if it does not exist.- Parameters:
dir
- directory to be created
-
createTmpdir
Creates a directory in the temp directory.- Parameters:
prefix
- the prefixsuffix
- the suffix- Returns:
- the directory
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
getTmpdir
-
toStringArray
-
getParentExtendedFile
Gets the parent asExtendedFile
. This method was introduced becauseFile.getParent()
andFile.getParentFile()
also exists.- Returns:
- the parent extended 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
-
endsWith
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
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
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
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
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? -
hashCode
-