SizeFileFilter (Commons IO 2.5)
Date: 2016-12-01

org.apache.commons.io.filefilter

## Class SizeFileFilter

- java.lang.Object
- - org.apache.commons.io.filefilter.AbstractFileFilter
  - - org.apache.commons.io.filefilter.SizeFileFilter

- All Implemented Interfaces:
    java.io.FileFilter, java.io.FilenameFilter, java.io.Serializable, IOFileFilter

      public class SizeFileFilter
      extends AbstractFileFilter
      implements java.io.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:

       File dir = new File(".");
       String[] files = dir.list( new SizeFileFilter(1024 * 1024) );
       for ( int i = 0; i < files.length; i++ ) {
           System.out.println(files[i]);
       }

  Since:
    1.2
  Version:
    $Id: SizeFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
  See Also:
    `FileFilterUtils.sizeFileFilter(long)`, `FileFilterUtils.sizeFileFilter(long, boolean)`, `FileFilterUtils.sizeRangeFileFilter(long, long)`, Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private boolean` | `acceptLarger` Whether the files accepted will be larger or smaller.
    `private static long` | `serialVersionUID`
    `private long` | `size` The size threshold.

  - ### Constructor Summary

    Constructors
    Constructor and 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

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `accept(java.io.File file)` Checks to see if the size of the file is favorable.
    `java.lang.String` | `toString()` Provide a String representaion of this file filter.

    - ### Methods inherited from class org.apache.commons.io.filefilter.AbstractFileFilter

      `accept`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### serialVersionUID

          private static final long serialVersionUID

      See Also:
        Constant Field Values

    - #### size

          private final long size

      The size threshold.

    - #### acceptLarger

          private final boolean acceptLarger

      Whether the files accepted will be larger or smaller.

  - ### Constructor Detail

    - #### 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
      Throws:
        `java.lang.IllegalArgumentException` - if the size is 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
        `acceptLarger` - if true, files equal to or larger are accepted, otherwise smaller ones (but not equal to)
      Throws:
        `java.lang.IllegalArgumentException` - if the size is negative

  - ### Method Detail

    - #### accept

          public boolean accept(java.io.File file)

      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.

      Specified by:
        `accept` in interface `java.io.FileFilter`
      Specified by:
        `accept` in interface `IOFileFilter`
      Overrides:
        `accept` in class `AbstractFileFilter`
      Parameters:
        `file` - the File to check
      Returns:
        true if the filename matches

    - #### toString

          public java.lang.String toString()

      Provide a String representaion of this file filter.
      Overrides:
        `toString` in class `AbstractFileFilter`
      Returns:
        a String representaion

Copyright (c) 2002-2016 Apache Software Foundation