Class FileEntry

  • All Implemented Interfaces:
    java.io.Serializable

    public class FileEntry
    extends java.lang.Object
    implements java.io.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.

    Deprecating Serialization

    Serialization is deprecated and will be removed in 3.0.

    Since:
    2.0
    See Also:
    FileAlterationObserver, Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      FileEntry​(java.io.File file)
      Constructs a new monitor for a specified File.
      FileEntry​(FileEntry parent, java.io.File file)
      Constructs a new monitor for a specified File.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      FileEntry[] getChildren()
      Gets the directory's files.
      java.io.File getFile()
      Gets the file being monitored.
      long getLastModified()
      Gets the last modified time from the last time it was checked.
      java.nio.file.attribute.FileTime getLastModifiedFileTime()
      Gets the last modified time from the last time it was checked.
      long getLength()
      Gets the length.
      int getLevel()
      Gets the level
      java.lang.String getName()
      Gets the file name.
      FileEntry getParent()
      Gets the parent entry.
      boolean isDirectory()
      Tests whether the file is a directory or not.
      boolean isExists()
      Tests whether the file existed the last time it was checked.
      FileEntry newChildInstance​(java.io.File file)
      Creates a new child instance.
      boolean refresh​(java.io.File file)
      Refreshes the attributes from the File, indicating whether the file has changed.
      void setChildren​(FileEntry... children)
      Sets the directory's files.
      void setDirectory​(boolean directory)
      Sets whether the file is a directory or not.
      void setExists​(boolean exists)
      Sets whether the file existed the last time it was checked.
      void setLastModified​(long lastModified)
      Sets the last modified time from the last time it was checked.
      void setLastModified​(java.nio.file.attribute.FileTime lastModified)
      Sets the last modified time from the last time it was checked.
      void setLength​(long length)
      Sets the length.
      void setName​(java.lang.String name)
      Sets the file name.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileEntry

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

        public FileEntry​(FileEntry parent,
                         java.io.File file)
        Constructs a new monitor for a specified File.
        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)
        Creates 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 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

        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.
      • 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