Source Code Cross Referenced for AgeFileFilter.java in  » Library » apache-common-IO » org » apache » commons » io » filefilter » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » apache common IO » org.apache.commons.io.filefilter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.io.filefilter;
018:
019:        import java.io.File;
020:        import java.util.Date;
021:
022:        import org.apache.commons.io.FileUtils;
023:
024:        /**
025:         * Filters files based on a cutoff time, can filter either newer
026:         * files or files equal to or older.
027:         * <p>
028:         * For example, to print all files and directories in the
029:         * current directory older than one day:
030:         *
031:         * <pre>
032:         * File dir = new File(".");
033:         * // We are interested in files older than one day
034:         * long cutoff = System.currentTimeMillis() - (24 * 60 * 60 * 1000);
035:         * String[] files = dir.list( new AgeFileFilter(cutoff) );
036:         * for ( int i = 0; i &lt; files.length; i++ ) {
037:         *     System.out.println(files[i]);
038:         * }
039:         * </pre>
040:         *
041:         * @author Rahul Akolkar
042:         * @version $Id: AgeFileFilter.java 463570 2006-10-13 06:14:41Z niallp $
043:         * @since Commons IO 1.2
044:         */
045:        public class AgeFileFilter extends AbstractFileFilter {
046:
047:            /** The cutoff time threshold. */
048:            private long cutoff;
049:            /** Whether the files accepted will be older or newer. */
050:            private boolean acceptOlder;
051:
052:            /**
053:             * Constructs a new age file filter for files equal to or older than
054:             * a certain cutoff
055:             *
056:             * @param cutoff  the threshold age of the files
057:             */
058:            public AgeFileFilter(long cutoff) {
059:                this (cutoff, true);
060:            }
061:
062:            /**
063:             * Constructs a new age file filter for files on any one side
064:             * of a certain cutoff.
065:             *
066:             * @param cutoff  the threshold age of the files
067:             * @param acceptOlder  if true, older files (at or before the cutoff)
068:             * are accepted, else newer ones (after the cutoff).
069:             */
070:            public AgeFileFilter(long cutoff, boolean acceptOlder) {
071:                this .acceptOlder = acceptOlder;
072:                this .cutoff = cutoff;
073:            }
074:
075:            /**
076:             * Constructs a new age file filter for files older than (at or before)
077:             * a certain cutoff date.
078:             *
079:             * @param cutoffDate  the threshold age of the files
080:             */
081:            public AgeFileFilter(Date cutoffDate) {
082:                this (cutoffDate, true);
083:            }
084:
085:            /**
086:             * Constructs a new age file filter for files on any one side
087:             * of a certain cutoff date.
088:             *
089:             * @param cutoffDate  the threshold age of the files
090:             * @param acceptOlder  if true, older files (at or before the cutoff)
091:             * are accepted, else newer ones (after the cutoff).
092:             */
093:            public AgeFileFilter(Date cutoffDate, boolean acceptOlder) {
094:                this (cutoffDate.getTime(), acceptOlder);
095:            }
096:
097:            /**
098:             * Constructs a new age file filter for files older than (at or before)
099:             * a certain File (whose last modification time will be used as reference).
100:             *
101:             * @param cutoffReference  the file whose last modification
102:             *        time is usesd as the threshold age of the files
103:             */
104:            public AgeFileFilter(File cutoffReference) {
105:                this (cutoffReference, true);
106:            }
107:
108:            /**
109:             * Constructs a new age file filter for files on any one side
110:             * of a certain File (whose last modification time will be used as
111:             * reference).
112:             *
113:             * @param cutoffReference  the file whose last modification
114:             *        time is usesd as the threshold age of the files
115:             * @param acceptOlder  if true, older files (at or before the cutoff)
116:             * are accepted, else newer ones (after the cutoff).
117:             */
118:            public AgeFileFilter(File cutoffReference, boolean acceptOlder) {
119:                this (cutoffReference.lastModified(), acceptOlder);
120:            }
121:
122:            //-----------------------------------------------------------------------
123:            /**
124:             * Checks to see if the last modification of the file matches cutoff
125:             * favorably.
126:             * <p>
127:             * If last modification time equals cutoff and newer files are required,
128:             * file <b>IS NOT</b> selected.
129:             * If last modification time equals cutoff and older files are required,
130:             * file <b>IS</b> selected.
131:             *
132:             * @param file  the File to check
133:             * @return true if the filename matches
134:             */
135:            public boolean accept(File file) {
136:                boolean newer = FileUtils.isFileNewer(file, cutoff);
137:                return acceptOlder ? !newer : newer;
138:            }
139:
140:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.