Class AgeFileFilter

  • All Implemented Interfaces:
    java.io.Serializable, FileFilter

    public class AgeFileFilter
    extends java.lang.Object
    implements FileFilter, java.io.Serializable
    Filters files based on a cutoff time, can filter either newer files or files equal to or older.

    For example, to print all files and directories in the current directory older than one day:

     FileSystemManager fsManager = VFS.getManager();
     FileObject dir = fsManager.toFileObject(new File("."));
     // We are interested in files older than one day
     long cutoff = System.currentTimeMillis() - (24 * 60 * 60 * 1000);
     AgeFileFilter filter = new AgeFileFilter(cutoff);
     FileObject[] files = dir.findFiles(new FileFilterSelector(filter));
     for (int i = 0; i < files.length; i++) {
         System.out.println(files[i]);
     }
     
    Since:
    2.4
    Author:
    This code was originally ported from Apache Commons IO File Filter
    See Also:
    "https://commons.apache.org/proper/commons-io/", Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      AgeFileFilter​(long cutoff)
      Constructs a new age file filter for files equal to or older than a certain cutoff.
      AgeFileFilter​(long cutoff, boolean acceptOlder)
      Constructs a new age file filter for files on any one side of a certain cutoff.
      AgeFileFilter​(java.util.Date cutoffDate)
      Constructs a new age file filter for files older than (at or before) a certain cutoff date.
      AgeFileFilter​(java.util.Date cutoffDate, boolean acceptOlder)
      Constructs a new age file filter for files on any one side of a certain cutoff date.
      AgeFileFilter​(FileObject cutoffReference)
      Constructs a new age file filter for files older than (at or before) a certain File (whose last modification time will be used as reference).
      AgeFileFilter​(FileObject cutoffReference, boolean acceptOlder)
      Constructs a new age file filter for files on any one side of a certain File (whose last modification time will be used as reference).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean accept​(FileSelectInfo fileInfo)
      Checks to see if the last modification of the file matches cutoff favorably.
      java.lang.String toString()
      Provide a String representation of this file filter.
      • Methods inherited from class java.lang.Object

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

      • AgeFileFilter

        public AgeFileFilter​(java.util.Date cutoffDate)
        Constructs a new age file filter for files older than (at or before) a certain cutoff date.
        Parameters:
        cutoffDate - the threshold age of the files
      • AgeFileFilter

        public AgeFileFilter​(java.util.Date cutoffDate,
                             boolean acceptOlder)
        Constructs a new age file filter for files on any one side of a certain cutoff date.
        Parameters:
        cutoffDate - the threshold age of the files
        acceptOlder - if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).
      • AgeFileFilter

        public AgeFileFilter​(FileObject cutoffReference)
                      throws FileSystemException
        Constructs a new age file filter for files older than (at or before) a certain File (whose last modification time will be used as reference).
        Parameters:
        cutoffReference - the file whose last modification time is used as the threshold age of the files
        Throws:
        FileSystemException - Error reading the last modification time from the reference file object.
      • AgeFileFilter

        public AgeFileFilter​(FileObject cutoffReference,
                             boolean acceptOlder)
                      throws FileSystemException
        Constructs a new age file filter for files on any one side of a certain File (whose last modification time will be used as reference).
        Parameters:
        cutoffReference - the file whose last modification time is used as the threshold age of the files
        acceptOlder - if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).
        Throws:
        FileSystemException - Error reading the last modification time from the reference file object.
      • AgeFileFilter

        public AgeFileFilter​(long cutoff)
        Constructs a new age file filter for files equal to or older than a certain cutoff.
        Parameters:
        cutoff - the threshold age of the files
      • AgeFileFilter

        public AgeFileFilter​(long cutoff,
                             boolean acceptOlder)
        Constructs a new age file filter for files on any one side of a certain cutoff.
        Parameters:
        cutoff - the threshold age of the files
        acceptOlder - if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).
    • Method Detail

      • accept

        public boolean accept​(FileSelectInfo fileInfo)
                       throws FileSystemException
        Checks to see if the last modification of the file matches cutoff favorably.

        If last modification time equals cutoff and newer files are required, file IS NOT selected. If last modification time equals cutoff and older files are required, file IS selected.

        Specified by:
        accept in interface FileFilter
        Parameters:
        fileInfo - the File to check
        Returns:
        true if the file name matches
        Throws:
        FileSystemException - Thrown for file system errors.
      • toString

        public java.lang.String toString()
        Provide a String representation of this file filter.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String representation