Class SizeFileFilter

java.lang.Object
org.apache.commons.vfs2.filter.SizeFileFilter
All Implemented Interfaces:
Serializable, FileFilter

public class SizeFileFilter extends Object implements FileFilter, Serializable
Filters files based on size, can filter either smaller files or files equal to or larger than a given threshold.

For example, to print all files and directories in the current directory whose size is greater than 1 MB:

 FileSystemManager fsManager = VFS.getManager();
 FileObject dir = fsManager.toFileObject(new File("."));
 SizeFileFilter filter = new SizeFileFilter(1024 * 1024);
 FileObject[] files = dir.findFiles(new FileFilterSelector(filter));
 for (int i = 0; i < files.length; i++) {
     System.out.println(files[i]);
 }
 
Since:
2.4
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final boolean
    Whether the files accepted will be larger or smaller.
    private static final long
     
    private final long
    The size threshold.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SizeFileFilter(long size)
    Constructs a new size file filter for files equal to or larger than a certain size.
    SizeFileFilter(long size, boolean acceptLarger)
    Constructs a new size file filter for files based on a certain size threshold.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    accept(FileSelectInfo fileSelectInfo)
    Checks to see if the size of the file is favorable.
    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
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • acceptLarger

      private final boolean acceptLarger
      Whether the files accepted will be larger or smaller.
    • size

      private final long size
      The size threshold.
  • Constructor Details

    • SizeFileFilter

      public SizeFileFilter(long size)
      Constructs a new size file filter for files equal to or larger than a certain size.
      Parameters:
      size - the threshold size of the files - Must be non-negative.
    • SizeFileFilter

      public SizeFileFilter(long size, boolean acceptLarger)
      Constructs a new size file filter for files based on a certain size threshold.
      Parameters:
      size - the threshold size of the files - Must be non-negative.
      acceptLarger - if true, files equal to or larger are accepted, otherwise smaller ones (but not equal to)
  • Method Details

    • accept

      public boolean accept(FileSelectInfo fileSelectInfo) throws FileSystemException
      Checks to see if the size of the file is favorable.

      If size equals threshold and smaller files are required, file IS NOT selected. If size equals threshold and larger files are required, file IS selected.

      Non-existing files return always false (will never be accepted).

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

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