org.apache.commons.io.filefilter
Class SizeFileFilter

java.lang.Object
  extended byorg.apache.commons.io.filefilter.AbstractFileFilter
      extended byorg.apache.commons.io.filefilter.SizeFileFilter
All Implemented Interfaces:
FileFilter, FilenameFilter, IOFileFilter

public class SizeFileFilter
extends AbstractFileFilter

Filters files based on size, can filter either larger or smaller files as compared to 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:
Commons IO 1.2
Version:
$Id: SizeFileFilter.java 360504 2006-01-01 17:49:18Z scolebourne $

Constructor Summary
SizeFileFilter(long size)
          Constructs a new size file filter for files 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
 boolean accept(File file)
          Checks to see if the size of the file is favorable.
 
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, toString, wait, wait, wait
 

Constructor Detail

SizeFileFilter

public SizeFileFilter(long size)
Constructs a new size file filter for files larger than a certain size.

Parameters:
size - the threshold size of the files
Throws:
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, larger files are accepted, else smaller ones
Throws:
IllegalArgumentException - if the size is negative
Method Detail

accept

public boolean accept(File file)
Checks to see if the size of the file is favorable. If size equals threshold, file is not selected.

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


Copyright © 2002-2006 The Apache Software Foundation. All Rights Reserved.