Package 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:
- FileFilter,- FilenameFilter,- Serializable,- FileVisitor<Path>,- PathMatcher,- PathFilter,- PathVisitor,- IOFileFilter
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:
Using Classic IO
 File dir = FileUtils.current();
 String[] files = dir.list(new SizeFileFilter(1024 * 1024));
 for (String file : files) {
     System.out.println(file);
 }
 
 Using NIO
final Path dir = PathUtils.current(); final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new SizeFileFilter(1024 * 1024)); // // Walk one directory Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); // visitor.getPathCounters().reset(); // // Walk directory tree Files.walkFileTree(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList());
Deprecating Serialization
Serialization is deprecated and will be removed in 3.0.
- Since:
- 1.2
- See Also:
- 
Field SummaryFields inherited from interface org.apache.commons.io.filefilter.IOFileFilterEMPTY_STRING_ARRAY
- 
Constructor SummaryConstructorsConstructorDescriptionSizeFileFilter(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 SummaryModifier and TypeMethodDescriptionbooleanTests to see if the size of the file is favorable.accept(Path file, BasicFileAttributes attributes) Tests to see if the size of the file is favorable.toString()Provide a String representation of this file filter.visitFile(Path file, BasicFileAttributes attrs) Methods inherited from class org.apache.commons.io.filefilter.AbstractFileFilteraccept, handle, postVisitDirectory, preVisitDirectory, visitFileFailedMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.io.filefilter.IOFileFilterand, matches, negate, or
- 
Constructor Details- 
SizeFileFilterConstructs a new size file filter for files equal to or larger than a certain size.- Parameters:
- size- the threshold size of the files
- Throws:
- IllegalArgumentException- if the size is negative
 
- 
SizeFileFilterConstructs 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:
- IllegalArgumentException- if the size is negative
 
 
- 
- 
Method Details- 
acceptTests 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:
- acceptin interface- FileFilter
- Specified by:
- acceptin interface- IOFileFilter
- Overrides:
- acceptin class- AbstractFileFilter
- Parameters:
- file- the File to check
- Returns:
- true if the file name matches
 
- 
acceptTests 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:
- acceptin interface- IOFileFilter
- Specified by:
- acceptin interface- PathFilter
- Parameters:
- file- the File to check
- attributes- the path's basic attributes (may be null).
- Returns:
- true if the file name matches
 
- 
toStringProvide a String representation of this file filter.- Overrides:
- toStringin class- AbstractFileFilter
- Returns:
- a String representation
 
- 
visitFile- Specified by:
- visitFilein interface- FileVisitor<Path>
- Overrides:
- visitFilein class- AbstractFileFilter
- Throws:
- IOException
 
 
-