Class FileChangedChecker


  • public class FileChangedChecker
    extends java.lang.Object
    This class is used to check for file modifications of the file time stamp and/or the file size.
    Author:
    Christopher Mindus
    • Constructor Summary

      Constructors 
      ConstructorDescription
      FileChangedChecker​(java.io.File file)
      Creates the file change checker instance.
      FileChangedChecker​(java.lang.String fileName)
      Creates the file change checker instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      java.lang.StringgetFileName()
      Gets the file name being checked.
      booleanhasChanged()
      Checks if the file has changed.
      booleanisNewerThan​(java.io.File file)
      Checks if this file is newer than the one specified.
      booleanisNewerThan​(java.lang.String fileName)
      Checks if this file is newer than the one specified.
      longlastModified()
      Returns the time that the file denoted by this abstract pathname was last modified.
      longlength()
      Returns the length of the file denoted by this abstract pathname.
      voidupdate()
      Requests an update of the file size and last modification time, if the file has been changed.
      • Methods inherited from class java.lang.Object

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

      • FileChangedChecker

        public FileChangedChecker​(java.io.File file)
        Creates the file change checker instance.
      • FileChangedChecker

        public FileChangedChecker​(java.lang.String fileName)
        Creates the file change checker instance.
    • Method Detail

      • getFileName

        public java.lang.String getFileName()
        Gets the file name being checked.
        Returns:
        The file name specified in the constructor or the path to the file name when the instance was constructed with the File parameter.
      • hasChanged

        public boolean hasChanged()
        Checks if the file has changed.
        Returns:
        true if the file has changed in size or last modified time, false otherwise.
      • update

        public void update()
        Requests an update of the file size and last modification time, if the file has been changed.
      • lastModified

        public long lastModified()
        Returns the time that the file denoted by this abstract pathname was last modified.
        Returns:
        A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs.
      • length

        public long length()
        Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.
        Returns:
        The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist. Some operating systems may return 0L for pathnames denoting system-dependent entities such as devices or pipes.
      • isNewerThan

        public boolean isNewerThan​(java.io.File file)
        Checks if this file is newer than the one specified. A new time stamp is read, the stored one is not used.
        Parameters:
        file - The file to compare last modified time with.
        Returns:
        true if this file is newer than the one specified in the parameter, false otherwise.
      • isNewerThan

        public boolean isNewerThan​(java.lang.String fileName)
        Checks if this file is newer than the one specified. A new time stamp is read, the stored one is not used.
        Parameters:
        fileName - The file name to compare last modified time with.
        Returns:
        true if this file is newer than the one specified in the parameter, false otherwise.