Class FileEntry

java.lang.Object
org.apache.commons.io.monitor.FileEntry
All Implemented Interfaces:
Serializable

public class FileEntry extends Object implements Serializable
The state of a file or directory, capturing the following File attributes at a point in time.

Custom Implementations Link icon

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.

Deprecating Serialization Link icon

Serialization is deprecated and will be removed in 3.0.

Since:
2.0
See Also:
  • Constructor Details Link icon

    • FileEntry Link icon

      public FileEntry(File file)
      Constructs a new monitor for a specified File.
      Parameters:
      file - The file being monitored
    • FileEntry Link icon

      public FileEntry(FileEntry parent, File file)
      Constructs a new monitor for a specified File.
      Parameters:
      parent - The parent.
      file - The file being monitored.
  • Method Details Link icon

    • getChildren Link icon

      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 Link icon

      public File getFile()
      Gets the file being monitored.
      Returns:
      the file being monitored
    • getLastModified Link icon

      public long getLastModified()
      Gets the last modified time from the last time it was checked.
      Returns:
      the last modified time in milliseconds.
    • getLastModifiedFileTime Link icon

      Gets the last modified time from the last time it was checked.
      Returns:
      the last modified time.
      Since:
      2.12.0
    • getLength Link icon

      public long getLength()
      Gets the length.
      Returns:
      the length
    • getLevel Link icon

      public int getLevel()
      Gets the level
      Returns:
      the level
    • getName Link icon

      public String getName()
      Gets the file name.
      Returns:
      the file name
    • getParent Link icon

      public FileEntry getParent()
      Gets the parent entry.
      Returns:
      the parent entry
    • isDirectory Link icon

      public boolean isDirectory()
      Tests whether the file is a directory or not.
      Returns:
      whether the file is a directory or not
    • isExists Link icon

      public boolean isExists()
      Tests whether the file existed the last time it was checked.
      Returns:
      whether the file existed
    • newChildInstance Link icon

      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 Link icon

      public boolean refresh(File file)
      Refreshes the attributes from the File, indicating whether the file has changed.

      This implementation refreshes the name, exists, directory, lastModified and length properties.

      The exists, directory, lastModified and length properties are compared for changes

      Parameters:
      file - the file instance to compare to
      Returns:
      true if the file has changed, otherwise false
    • setChildren Link icon

      public void setChildren(FileEntry... children)
      Sets the directory's files.
      Parameters:
      children - This directory's files, may be null
    • setDirectory Link icon

      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 Link icon

      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 Link icon

      public void setLastModified(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 Link icon

      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.
    • setLength Link icon

      public void setLength(long length)
      Sets the length.
      Parameters:
      length - the length
    • setName Link icon

      public void setName(String name)
      Sets the file name.
      Parameters:
      name - the file name