Package org.apache.commons.io.monitor
Class FileEntry
java.lang.Object
org.apache.commons.io.monitor.FileEntry
- All Implemented Interfaces:
Serializable
The state of a file or directory, capturing the following
File attributes at a point in time.
- File Name (see
File.getName()) - Exists - whether the file exists or not (see
File.exists()) - Directory - whether the file is a directory or not (see
File.isDirectory()) - Last Modified Date/Time (see
FileUtils.lastModifiedUnchecked(File)) - Length (see
File.length()) - directories treated as zero - Children - contents of a directory (see
File.listFiles(java.io.FileFilter))
Custom Implementations
If the state of additional File attributes is required then create a custom
FileEntry with properties for those attributes. Override the
newChildInstance(File) to return a new instance of the appropriate type.
You may also want to override the refresh(File) method.
- Since:
- 2.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn the directory's files.getFile()Return the file being monitored.longReturn the last modified time from the last time it was checked.longReturn the length.intgetLevel()Return the levelgetName()Return the file name.Return the parent entry.booleanIndicate whether the file is a directory or not.booleanisExists()Indicate whether the file existed the last time it was checked.newChildInstance(File file) Create a new child instance.booleanRefresh the attributes from theFile, indicating whether the file has changed.voidsetChildren(FileEntry... children) Set the directory's files.voidsetDirectory(boolean directory) Set whether the file is a directory or not.voidsetExists(boolean exists) Set whether the file existed the last time it was checked.voidsetLastModified(long lastModified) Return the last modified time from the last time it was checked.voidsetLength(long length) Set the length.voidSet the file name.
-
Constructor Details
-
Method Details
-
refresh
Refresh the attributes from theFile, indicating whether the file has changed.This implementation refreshes the
name,exists,directory,lastModifiedandlengthproperties.The
exists,directory,lastModifiedandlengthproperties are compared for changes- Parameters:
file- the file instance to compare to- Returns:
trueif the file has changed, otherwisefalse
-
newChildInstance
Create a new child instance.Custom implementations should override this method to return a new instance of the appropriate type.
- Parameters:
file- The child file- Returns:
- a new child instance
-
getParent
Return the parent entry.- Returns:
- the parent entry
-
getLevel
Return the level- Returns:
- the level
-
getChildren
Return the directory's files.- Returns:
- This directory's files or an empty array if the file is not a directory or the directory is empty
-
setChildren
Set the directory's files.- Parameters:
children- This directory's files, may be null
-
getFile
Return the file being monitored.- Returns:
- the file being monitored
-
getName
Return the file name.- Returns:
- the file name
-
setName
Set the file name.- Parameters:
name- the file name
-
getLastModified
Return the last modified time from the last time it was checked.- Returns:
- the last modified time
-
setLastModified
Return the last modified time from the last time it was checked.- Parameters:
lastModified- The last modified time
-
getLength
Return the length.- Returns:
- the length
-
setLength
Set the length.- Parameters:
length- the length
-
isExists
Indicate whether the file existed the last time it was checked.- Returns:
- whether the file existed
-
setExists
Set whether the file existed the last time it was checked.- Parameters:
exists- whether the file exists or not
-
isDirectory
Indicate whether the file is a directory or not.- Returns:
- whether the file is a directory or not
-
setDirectory
Set whether the file is a directory or not.- Parameters:
directory- whether the file is a directory or not
-