001// Copyright (c) 2001 Hursh Jain (http://www.mollypages.org) 002// The Molly framework is freely distributable under the terms of an 003// MIT-style license. For details, see the molly pages web site at: 004// http://www.mollypages.org/. Use, modify, have fun ! 005 006package fc.io.fileselectors; 007 008import java.io.*; 009import java.util.*; 010 011/** 012Filters a list of files greater or equal to some specified size. 013Negative values or a zero size value chooses all files. Note: file 014sizes are only applicable to normal files, <b>not</b> directories. 015(a java.io.File api restriction). If the target file is a directory, 016this selector always returns <b>true</b>. 017 018@author hursh jain 019@date 3/24/2002 020**/ 021 022public class MinSizeSelector extends ChainedFileSelector 023{ 024long filesize; 025/** 026@param filesize the required file size in bytes 027*/ 028public MinSizeSelector(long filesize) { 029 this(filesize, null); 030 } 031 032/** 033@param filesize the required file size in bytes 034@param filter the next filter in the chain 035*/ 036public MinSizeSelector(long filesize, ChainedFileSelector filter) { 037 super(filter); 038 this.filesize = filesize; 039 } 040 041protected boolean thisfilter(File name) { 042 if ( name.isDirectory() ) return true; 043 if ( name.length() >= filesize ) return true; 044 //System.out.println("rejecting: " + name + ", size = " + name.length()); 045 return false; 046 } 047 048public static void main(String[] args) throws Exception 049 { 050 new Test(); 051 } 052 053/** 054Unit Test History 055<pre> 056Class Version Tester Status Notes 0571.0 hj passed 058</pre> 059*/ 060static private class Test { 061Test() throws Exception 062 { 063 File startdir = new File("c:\\temp"); 064 ChainedFileSelector sel = new MinSizeSelector(4); 065 File[] files = startdir.listFiles(sel); 066 List list = Arrays.asList(files); 067 System.out.println("total="+ list.size() + ", files=" + list); 068 } 069} //~class Test 070 071}