Package org.apache.commons.io.monitor
Class FileEntry
- java.lang.Object
-
- org.apache.commons.io.monitor.FileEntry
-
- All Implemented Interfaces:
java.io.Serializable
public class FileEntry extends java.lang.Object implements java.io.SerializableThe state of a file or directory, capturing the followingFileattributes 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
Fileattributes is required then create a customFileEntrywith properties for those attributes. Override thenewChildInstance(File)to return a new instance of the appropriate type. You may also want to override therefresh(File)method.Deprecating Serialization
Serialization is deprecated and will be removed in 3.0.
- Since:
- 2.0
- See Also:
FileAlterationObserver, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private FileEntry[]childrenMy children.private booleandirectoryWhether the file is a directory or not.(package private) static FileEntry[]EMPTY_FILE_ENTRY_ARRAYprivate booleanexistsWhether the file exists.private java.io.FilefileMonitored file.private SerializableFileTimelastModifiedThe file's last modified timestamp.private longlengthThe file's length.private java.lang.StringnameMonitored file name.private FileEntryparentThe parent.private static longserialVersionUID
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileEntry[]getChildren()Gets the directory's files.java.io.FilegetFile()Gets the file being monitored.longgetLastModified()Gets the last modified time from the last time it was checked.java.nio.file.attribute.FileTimegetLastModifiedFileTime()Gets the last modified time from the last time it was checked.longgetLength()Gets the length.intgetLevel()Gets the leveljava.lang.StringgetName()Gets the file name.FileEntrygetParent()Gets the parent entry.booleanisDirectory()Tests whether the file is a directory or not.booleanisExists()Tests whether the file existed the last time it was checked.FileEntrynewChildInstance(java.io.File file)Constructs a new child instance.booleanrefresh(java.io.File file)Refreshes the attributes from theFile, indicating whether the file has changed.voidsetChildren(FileEntry... children)Sets the directory's files.voidsetDirectory(boolean directory)Sets whether the file is a directory or not.voidsetExists(boolean exists)Sets whether the file existed the last time it was checked.voidsetLastModified(long lastModified)Sets the last modified time from the last time it was checked.voidsetLastModified(java.nio.file.attribute.FileTime lastModified)Sets the last modified time from the last time it was checked.(package private) voidsetLastModified(SerializableFileTime lastModified)voidsetLength(long length)Sets the length.voidsetName(java.lang.String name)Sets the file name.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
EMPTY_FILE_ENTRY_ARRAY
static final FileEntry[] EMPTY_FILE_ENTRY_ARRAY
-
parent
private final FileEntry parent
The parent.
-
children
private FileEntry[] children
My children.
-
file
private final java.io.File file
Monitored file.
-
name
private java.lang.String name
Monitored file name.
-
exists
private boolean exists
Whether the file exists.
-
directory
private boolean directory
Whether the file is a directory or not.
-
lastModified
private SerializableFileTime lastModified
The file's last modified timestamp.
-
length
private long length
The file's length.
-
-
Constructor Detail
-
FileEntry
public FileEntry(java.io.File file)
Constructs a new monitor for a specifiedFile.- Parameters:
file- The file being monitored
-
FileEntry
public FileEntry(FileEntry parent, java.io.File file)
Constructs a new monitor for a specifiedFile.- Parameters:
parent- The parent.file- The file being monitored.
-
-
Method Detail
-
getChildren
public FileEntry[] getChildren()
Gets 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
-
getFile
public java.io.File getFile()
Gets the file being monitored.- Returns:
- the file being monitored
-
getLastModified
public long getLastModified()
Gets the last modified time from the last time it was checked.- Returns:
- the last modified time in milliseconds.
-
getLastModifiedFileTime
public java.nio.file.attribute.FileTime getLastModifiedFileTime()
Gets the last modified time from the last time it was checked.- Returns:
- the last modified time.
- Since:
- 2.12.0
-
getLength
public long getLength()
Gets the length.- Returns:
- the length
-
getLevel
public int getLevel()
Gets the level- Returns:
- the level
-
getName
public java.lang.String getName()
Gets the file name.- Returns:
- the file name
-
getParent
public FileEntry getParent()
Gets the parent entry.- Returns:
- the parent entry
-
isDirectory
public boolean isDirectory()
Tests whether the file is a directory or not.- Returns:
- whether the file is a directory or not
-
isExists
public boolean isExists()
Tests whether the file existed the last time it was checked.- Returns:
- whether the file existed
-
newChildInstance
public FileEntry newChildInstance(java.io.File file)
Constructs 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
-
refresh
public boolean refresh(java.io.File file)
Refreshes 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
-
setChildren
public void setChildren(FileEntry... children)
Sets the directory's files.- Parameters:
children- This directory's files, may be null
-
setDirectory
public void setDirectory(boolean directory)
Sets whether the file is a directory or not.- Parameters:
directory- whether the file is a directory or not
-
setExists
public void setExists(boolean exists)
Sets whether the file existed the last time it was checked.- Parameters:
exists- whether the file exists or not
-
setLastModified
public void setLastModified(java.nio.file.attribute.FileTime lastModified)
Sets the last modified time from the last time it was checked.- Parameters:
lastModified- The last modified time.- Since:
- 2.12.0
-
setLastModified
public void setLastModified(long lastModified)
Sets the last modified time from the last time it was checked.- Parameters:
lastModified- The last modified time in milliseconds.
-
setLastModified
void setLastModified(SerializableFileTime lastModified)
-
setLength
public void setLength(long length)
Sets the length.- Parameters:
length- the length
-
setName
public void setName(java.lang.String name)
Sets the file name.- Parameters:
name- the file name
-
-