This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push: new 7c6b855 Sort members. 7c6b855 is described below commit 7c6b855e2d10b318d08c1cf6996d5a92d3df8dc8 Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Sun Sep 27 11:22:55 2020 -0400 Sort members. --- .../commons/io/filefilter/AgeFileFilter.java | 50 +- .../commons/io/filefilter/AndFileFilter.java | 86 +-- .../io/filefilter/CanExecuteFileFilter.java | 4 +- .../commons/io/filefilter/CanReadFileFilter.java | 4 +- .../commons/io/filefilter/CanWriteFileFilter.java | 4 +- .../commons/io/filefilter/DelegateFileFilter.java | 24 +- .../commons/io/filefilter/DirectoryFileFilter.java | 2 +- .../commons/io/filefilter/EmptyFileFilter.java | 4 +- .../commons/io/filefilter/FalseFileFilter.java | 2 +- .../commons/io/filefilter/FileFileFilter.java | 2 +- .../commons/io/filefilter/FileFilterUtils.java | 788 ++++++++++----------- .../commons/io/filefilter/HiddenFileFilter.java | 4 +- 12 files changed, 487 insertions(+), 487 deletions(-) diff --git a/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java index e280830..15111ea 100644 --- a/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java @@ -51,34 +51,11 @@ public class AgeFileFilter extends AbstractFileFilter implements Serializable { private static final long serialVersionUID = -2132740084016138541L; - /** The cutoff time threshold. */ - private final long cutoff; - /** Whether the files accepted will be older or newer. */ private final boolean acceptOlder; - /** - * Constructs a new age file filter for files equal to or older than - * a certain cutoff - * - * @param cutoff the threshold age of the files - */ - public AgeFileFilter(final long cutoff) { - this(cutoff, true); - } - - /** - * Constructs a new age file filter for files on any one side - * of a certain cutoff. - * - * @param cutoff the threshold age of the files - * @param acceptOlder if true, older files (at or before the cutoff) - * are accepted, else newer ones (after the cutoff). - */ - public AgeFileFilter(final long cutoff, final boolean acceptOlder) { - this.acceptOlder = acceptOlder; - this.cutoff = cutoff; - } + /** The cutoff time threshold. */ + private final long cutoff; /** * Constructs a new age file filter for files older than (at or before) @@ -127,6 +104,29 @@ public class AgeFileFilter extends AbstractFileFilter implements Serializable { this(cutoffReference.lastModified(), acceptOlder); } + /** + * Constructs a new age file filter for files equal to or older than + * a certain cutoff + * + * @param cutoff the threshold age of the files + */ + public AgeFileFilter(final long cutoff) { + this(cutoff, true); + } + + /** + * Constructs a new age file filter for files on any one side + * of a certain cutoff. + * + * @param cutoff the threshold age of the files + * @param acceptOlder if true, older files (at or before the cutoff) + * are accepted, else newer ones (after the cutoff). + */ + public AgeFileFilter(final long cutoff, final boolean acceptOlder) { + this.acceptOlder = acceptOlder; + this.cutoff = cutoff; + } + //----------------------------------------------------------------------- /** * Checks to see if the last modification of the file matches cutoff diff --git a/src/main/java/org/apache/commons/io/filefilter/AndFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/AndFileFilter.java index e585b29..7d889ca 100644 --- a/src/main/java/org/apache/commons/io/filefilter/AndFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/AndFileFilter.java @@ -53,6 +53,22 @@ public class AndFileFilter } /** + * Constructs a new file filter that ANDs the result of two other filters. + * + * @param filter1 the first filter, must not be null + * @param filter2 the second filter, must not be null + * @throws IllegalArgumentException if either filter is null + */ + public AndFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) { + if (filter1 == null || filter2 == null) { + throw new IllegalArgumentException("The filters must not be null"); + } + this.fileFilters = new ArrayList<>(2); + addFileFilter(filter1); + addFileFilter(filter2); + } + + /** * Constructs a new instance of <code>AndFileFilter</code> * with the specified list of filters. * @@ -68,19 +84,35 @@ public class AndFileFilter } /** - * Constructs a new file filter that ANDs the result of two other filters. - * - * @param filter1 the first filter, must not be null - * @param filter2 the second filter, must not be null - * @throws IllegalArgumentException if either filter is null + * {@inheritDoc} */ - public AndFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) { - if (filter1 == null || filter2 == null) { - throw new IllegalArgumentException("The filters must not be null"); + @Override + public boolean accept(final File file) { + if (this.fileFilters.isEmpty()) { + return false; } - this.fileFilters = new ArrayList<>(2); - addFileFilter(filter1); - addFileFilter(filter2); + for (final IOFileFilter fileFilter : fileFilters) { + if (!fileFilter.accept(file)) { + return false; + } + } + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean accept(final File file, final String name) { + if (this.fileFilters.isEmpty()) { + return false; + } + for (final IOFileFilter fileFilter : fileFilters) { + if (!fileFilter.accept(file, name)) { + return false; + } + } + return true; } /** @@ -117,38 +149,6 @@ public class AndFileFilter } /** - * {@inheritDoc} - */ - @Override - public boolean accept(final File file) { - if (this.fileFilters.isEmpty()) { - return false; - } - for (final IOFileFilter fileFilter : fileFilters) { - if (!fileFilter.accept(file)) { - return false; - } - } - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean accept(final File file, final String name) { - if (this.fileFilters.isEmpty()) { - return false; - } - for (final IOFileFilter fileFilter : fileFilters) { - if (!fileFilter.accept(file, name)) { - return false; - } - } - return true; - } - - /** * Provide a String representation of this file filter. * * @return a String representation diff --git a/src/main/java/org/apache/commons/io/filefilter/CanExecuteFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/CanExecuteFileFilter.java index 540de6b..32fd43d 100644 --- a/src/main/java/org/apache/commons/io/filefilter/CanExecuteFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/CanExecuteFileFilter.java @@ -50,14 +50,14 @@ import java.io.Serializable; */ public class CanExecuteFileFilter extends AbstractFileFilter implements Serializable { - private static final long serialVersionUID = 3179904805251622989L; - /** Singleton instance of <i>executable</i> filter */ public static final IOFileFilter CAN_EXECUTE = new CanExecuteFileFilter(); /** Singleton instance of not <i>executable</i> filter */ public static final IOFileFilter CANNOT_EXECUTE = new NotFileFilter(CAN_EXECUTE); + private static final long serialVersionUID = 3179904805251622989L; + /** * Restrictive constructor. */ diff --git a/src/main/java/org/apache/commons/io/filefilter/CanReadFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/CanReadFileFilter.java index 35ab0be..dcd7a7f 100644 --- a/src/main/java/org/apache/commons/io/filefilter/CanReadFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/CanReadFileFilter.java @@ -62,8 +62,6 @@ import java.io.Serializable; */ public class CanReadFileFilter extends AbstractFileFilter implements Serializable { - private static final long serialVersionUID = 3179904805251622989L; - /** Singleton instance of <i>readable</i> filter */ public static final IOFileFilter CAN_READ = new CanReadFileFilter(); @@ -74,6 +72,8 @@ public class CanReadFileFilter extends AbstractFileFilter implements Serializabl public static final IOFileFilter READ_ONLY = new AndFileFilter(CAN_READ, CanWriteFileFilter.CANNOT_WRITE); + private static final long serialVersionUID = 3179904805251622989L; + /** * Restrictive constructor. */ diff --git a/src/main/java/org/apache/commons/io/filefilter/CanWriteFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/CanWriteFileFilter.java index 52e5b8d..e1a41b2 100644 --- a/src/main/java/org/apache/commons/io/filefilter/CanWriteFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/CanWriteFileFilter.java @@ -54,14 +54,14 @@ import java.io.Serializable; */ public class CanWriteFileFilter extends AbstractFileFilter implements Serializable { - private static final long serialVersionUID = 5132005214688990379L; - /** Singleton instance of <i>writable</i> filter */ public static final IOFileFilter CAN_WRITE = new CanWriteFileFilter(); /** Singleton instance of not <i>writable</i> filter */ public static final IOFileFilter CANNOT_WRITE = new NotFileFilter(CAN_WRITE); + private static final long serialVersionUID = 5132005214688990379L; + /** * Restrictive constructor. */ diff --git a/src/main/java/org/apache/commons/io/filefilter/DelegateFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/DelegateFileFilter.java index 9452739..380a2ef 100644 --- a/src/main/java/org/apache/commons/io/filefilter/DelegateFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/DelegateFileFilter.java @@ -33,35 +33,35 @@ import java.io.Serializable; public class DelegateFileFilter extends AbstractFileFilter implements Serializable { private static final long serialVersionUID = -8723373124984771318L; - /** The Filename filter */ - private final FilenameFilter filenameFilter; /** The File filter */ private final FileFilter fileFilter; + /** The Filename filter */ + private final FilenameFilter filenameFilter; /** - * Constructs a delegate file filter around an existing FilenameFilter. + * Constructs a delegate file filter around an existing FileFilter. * * @param filter the filter to decorate */ - public DelegateFileFilter(final FilenameFilter filter) { + public DelegateFileFilter(final FileFilter filter) { if (filter == null) { - throw new IllegalArgumentException("The FilenameFilter must not be null"); + throw new IllegalArgumentException("The FileFilter must not be null"); } - this.filenameFilter = filter; - this.fileFilter = null; + this.fileFilter = filter; + this.filenameFilter = null; } /** - * Constructs a delegate file filter around an existing FileFilter. + * Constructs a delegate file filter around an existing FilenameFilter. * * @param filter the filter to decorate */ - public DelegateFileFilter(final FileFilter filter) { + public DelegateFileFilter(final FilenameFilter filter) { if (filter == null) { - throw new IllegalArgumentException("The FileFilter must not be null"); + throw new IllegalArgumentException("The FilenameFilter must not be null"); } - this.fileFilter = filter; - this.filenameFilter = null; + this.filenameFilter = filter; + this.fileFilter = null; } /** diff --git a/src/main/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java index 0997510..2298ce1 100644 --- a/src/main/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java @@ -40,7 +40,6 @@ import java.io.Serializable; */ public class DirectoryFileFilter extends AbstractFileFilter implements Serializable { - private static final long serialVersionUID = -5148237843784525732L; /** * Singleton instance of directory filter. * @since 1.3 @@ -53,6 +52,7 @@ public class DirectoryFileFilter extends AbstractFileFilter implements Serializa * values when using static imports. */ public static final IOFileFilter INSTANCE = DIRECTORY; + private static final long serialVersionUID = -5148237843784525732L; /** * Restrictive constructor. diff --git a/src/main/java/org/apache/commons/io/filefilter/EmptyFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/EmptyFileFilter.java index 3b0e36c..2914951 100644 --- a/src/main/java/org/apache/commons/io/filefilter/EmptyFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/EmptyFileFilter.java @@ -53,14 +53,14 @@ import java.io.Serializable; */ public class EmptyFileFilter extends AbstractFileFilter implements Serializable { - private static final long serialVersionUID = 3631422087512832211L; - /** Singleton instance of <i>empty</i> filter */ public static final IOFileFilter EMPTY = new EmptyFileFilter(); /** Singleton instance of <i>not-empty</i> filter */ public static final IOFileFilter NOT_EMPTY = new NotFileFilter(EMPTY); + private static final long serialVersionUID = 3631422087512832211L; + /** * Restrictive constructor. */ diff --git a/src/main/java/org/apache/commons/io/filefilter/FalseFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/FalseFileFilter.java index 24b3f93..47ad394 100644 --- a/src/main/java/org/apache/commons/io/filefilter/FalseFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/FalseFileFilter.java @@ -29,7 +29,6 @@ import java.io.Serializable; */ public class FalseFileFilter implements IOFileFilter, Serializable { - private static final long serialVersionUID = 6210271677940926200L; /** * Singleton instance of false filter. * @since 1.3 @@ -42,6 +41,7 @@ public class FalseFileFilter implements IOFileFilter, Serializable { * values when using static imports. */ public static final IOFileFilter INSTANCE = FALSE; + private static final long serialVersionUID = 6210271677940926200L; /** * Restrictive constructor. diff --git a/src/main/java/org/apache/commons/io/filefilter/FileFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/FileFileFilter.java index b42c846..e639b61 100644 --- a/src/main/java/org/apache/commons/io/filefilter/FileFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/FileFileFilter.java @@ -39,9 +39,9 @@ import java.io.Serializable; */ public class FileFileFilter extends AbstractFileFilter implements Serializable { - private static final long serialVersionUID = 5345244090827540862L; /** Singleton instance of file filter */ public static final IOFileFilter FILE = new FileFileFilter(); + private static final long serialVersionUID = 5345244090827540862L; /** * Restrictive constructor. diff --git a/src/main/java/org/apache/commons/io/filefilter/FileFilterUtils.java b/src/main/java/org/apache/commons/io/filefilter/FileFilterUtils.java index 9ff77ac..761cd64 100644 --- a/src/main/java/org/apache/commons/io/filefilter/FileFilterUtils.java +++ b/src/main/java/org/apache/commons/io/filefilter/FileFilterUtils.java @@ -40,13 +40,183 @@ import org.apache.commons.io.IOCase; */ public class FileFilterUtils { + //----------------------------------------------------------------------- + /* Constructed on demand and then cached */ + private static final IOFileFilter cvsFilter = notFileFilter( + and(directoryFileFilter(), nameFileFilter("CVS"))); + + //----------------------------------------------------------------------- + + /* Constructed on demand and then cached */ + private static final IOFileFilter svnFilter = notFileFilter( + and(directoryFileFilter(), nameFileFilter(".svn"))); + /** - * FileFilterUtils is not normally instantiated. + * Returns a filter that returns true if the file was last modified before + * or at the specified cutoff date. + * + * @param cutoffDate the time threshold + * @return an appropriately configured age file filter + * @see AgeFileFilter + * @since 1.2 */ - public FileFilterUtils() { + public static IOFileFilter ageFileFilter(final Date cutoffDate) { + return new AgeFileFilter(cutoffDate); + } + + /** + * Returns a filter that filters files based on a cutoff date. + * + * @param cutoffDate the time threshold + * @param acceptOlder if true, older files get accepted, if false, newer + * @return an appropriately configured age file filter + * @see AgeFileFilter + * @since 1.2 + */ + public static IOFileFilter ageFileFilter(final Date cutoffDate, final boolean acceptOlder) { + return new AgeFileFilter(cutoffDate, acceptOlder); + } + + /** + * Returns a filter that returns true if the file was last modified before + * or at the same time as the specified reference file. + * + * @param cutoffReference the file whose last modification + * time is used as the threshold age of the files + * @return an appropriately configured age file filter + * @see AgeFileFilter + * @since 1.2 + */ + public static IOFileFilter ageFileFilter(final File cutoffReference) { + return new AgeFileFilter(cutoffReference); + } + + /** + * Returns a filter that filters files based on a cutoff reference file. + * + * @param cutoffReference the file whose last modification + * time is used as the threshold age of the files + * @param acceptOlder if true, older files get accepted, if false, newer + * @return an appropriately configured age file filter + * @see AgeFileFilter + * @since 1.2 + */ + public static IOFileFilter ageFileFilter(final File cutoffReference, final boolean acceptOlder) { + return new AgeFileFilter(cutoffReference, acceptOlder); + } + + //----------------------------------------------------------------------- + /** + * Returns a filter that returns true if the file was last modified before + * or at the specified cutoff time. + * + * @param cutoff the time threshold + * @return an appropriately configured age file filter + * @see AgeFileFilter + * @since 1.2 + */ + public static IOFileFilter ageFileFilter(final long cutoff) { + return new AgeFileFilter(cutoff); + } + + /** + * Returns a filter that filters files based on a cutoff time. + * + * @param cutoff the time threshold + * @param acceptOlder if true, older files get accepted, if false, newer + * @return an appropriately configured age file filter + * @see AgeFileFilter + * @since 1.2 + */ + public static IOFileFilter ageFileFilter(final long cutoff, final boolean acceptOlder) { + return new AgeFileFilter(cutoff, acceptOlder); + } + + /** + * Returns a filter that ANDs the specified filters. + * + * @param filters the IOFileFilters that will be ANDed together. + * @return a filter that ANDs the specified filters + * + * @throws IllegalArgumentException if the filters are null or contain a + * null value. + * @see AndFileFilter + * @since 2.0 + */ + public static IOFileFilter and(final IOFileFilter... filters) { + return new AndFileFilter(toList(filters)); + } + + //----------------------------------------------------------------------- + /** + * Returns a filter that ANDs the two specified filters. + * + * @param filter1 the first filter + * @param filter2 the second filter + * @return a filter that ANDs the two specified filters + * @see #and(IOFileFilter...) + * @see AndFileFilter + * @deprecated use {@link #and(IOFileFilter...)} + */ + @Deprecated + public static IOFileFilter andFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) { + return new AndFileFilter(filter1, filter2); } //----------------------------------------------------------------------- + /** + * Returns an <code>IOFileFilter</code> that wraps the + * <code>FileFilter</code> instance. + * + * @param filter the filter to be wrapped + * @return a new filter that implements IOFileFilter + * @see DelegateFileFilter + */ + public static IOFileFilter asFileFilter(final FileFilter filter) { + return new DelegateFileFilter(filter); + } + + /** + * Returns an <code>IOFileFilter</code> that wraps the + * <code>FilenameFilter</code> instance. + * + * @param filter the filter to be wrapped + * @return a new filter that implements IOFileFilter + * @see DelegateFileFilter + */ + public static IOFileFilter asFileFilter(final FilenameFilter filter) { + return new DelegateFileFilter(filter); + } + + /** + * Returns a filter that checks if the file is a directory. + * + * @return file filter that accepts only directories and not files + * @see DirectoryFileFilter#DIRECTORY + */ + public static IOFileFilter directoryFileFilter() { + return DirectoryFileFilter.DIRECTORY; + } + + /** + * Returns a filter that always returns false. + * + * @return a false filter + * @see FalseFileFilter#FALSE + */ + public static IOFileFilter falseFileFilter() { + return FalseFileFilter.FALSE; + } + + /** + * Returns a filter that checks if the file is a file (and not a directory). + * + * @return file filter that accepts only files and not directories + * @see FileFileFilter#FILE + */ + public static IOFileFilter fileFileFilter() { + return FileFileFilter.FILE; + } /** * <p> @@ -127,6 +297,46 @@ public class FileFilterUtils { /** * <p> * Applies an {@link IOFileFilter} to the provided {@link File} + * objects and appends the accepted files to the other supplied collection. + * </p> + * + * <pre> + * List<File> files = ... + * List<File> directories = FileFilterUtils.filterList(files, + * FileFilterUtils.sizeFileFilter(FileUtils.FIFTY_MB), + * new ArrayList<File>()); + * </pre> + * @param filter the filter to apply to the collection of files. + * @param files the collection of files to apply the filter to. + * @param acceptedFiles the list of files to add accepted files to. + * + * @param <T> the type of the file collection. + * @return a subset of <code>files</code> that is accepted by the + * file filter. + * @throws IllegalArgumentException if the filter is {@code null} + * or <code>files</code> contains a {@code null} value. + */ + private static <T extends Collection<File>> T filter(final IOFileFilter filter, + final Iterable<File> files, final T acceptedFiles) { + if (filter == null) { + throw new IllegalArgumentException("file filter is null"); + } + if (files != null) { + for (final File file : files) { + if (file == null) { + throw new IllegalArgumentException("file collection contains null"); + } + if (filter.accept(file)) { + acceptedFiles.add(file); + } + } + } + return acceptedFiles; + } + + /** + * <p> + * Applies an {@link IOFileFilter} to the provided {@link File} * objects. The resulting list is a subset of the original files that * matches the provided filter. * </p> @@ -149,8 +359,9 @@ public class FileFilterUtils { * or <code>files</code> contains a {@code null} value. * @since 2.0 */ - public static List<File> filterList(final IOFileFilter filter, final Iterable<File> files) { - return filter(filter, files, new ArrayList<>()); + public static List<File> filterList(final IOFileFilter filter, final File... files) { + final File[] acceptedFiles = filter(filter, files); + return Arrays.asList(acceptedFiles); } /** @@ -178,9 +389,8 @@ public class FileFilterUtils { * or <code>files</code> contains a {@code null} value. * @since 2.0 */ - public static List<File> filterList(final IOFileFilter filter, final File... files) { - final File[] acceptedFiles = filter(filter, files); - return Arrays.asList(acceptedFiles); + public static List<File> filterList(final IOFileFilter filter, final Iterable<File> files) { + return filter(filter, files, new ArrayList<>()); } /** @@ -245,357 +455,229 @@ public class FileFilterUtils { } /** - * <p> - * Applies an {@link IOFileFilter} to the provided {@link File} - * objects and appends the accepted files to the other supplied collection. - * </p> + * Returns a filter that accepts files that begin with the provided magic + * number. * - * <pre> - * List<File> files = ... - * List<File> directories = FileFilterUtils.filterList(files, - * FileFilterUtils.sizeFileFilter(FileUtils.FIFTY_MB), - * new ArrayList<File>()); - * </pre> - * @param filter the filter to apply to the collection of files. - * @param files the collection of files to apply the filter to. - * @param acceptedFiles the list of files to add accepted files to. + * @param magicNumber the magic number (byte sequence) to match at the + * beginning of each file. * - * @param <T> the type of the file collection. - * @return a subset of <code>files</code> that is accepted by the - * file filter. - * @throws IllegalArgumentException if the filter is {@code null} - * or <code>files</code> contains a {@code null} value. + * @return an IOFileFilter that accepts files beginning with the provided + * magic number. + * + * @throws IllegalArgumentException if <code>magicNumber</code> is + * {@code null} or is of length zero. + * @see MagicNumberFileFilter + * @since 2.0 */ - private static <T extends Collection<File>> T filter(final IOFileFilter filter, - final Iterable<File> files, final T acceptedFiles) { - if (filter == null) { - throw new IllegalArgumentException("file filter is null"); - } - if (files != null) { - for (final File file : files) { - if (file == null) { - throw new IllegalArgumentException("file collection contains null"); - } - if (filter.accept(file)) { - acceptedFiles.add(file); - } - } - } - return acceptedFiles; - } - - /** - * Returns a filter that returns true if the file name starts with the specified text. - * - * @param prefix the file name prefix - * @return a prefix checking filter - * @see PrefixFileFilter - */ - public static IOFileFilter prefixFileFilter(final String prefix) { - return new PrefixFileFilter(prefix); - } - - /** - * Returns a filter that returns true if the file name starts with the specified text. - * - * @param prefix the file name prefix - * @param caseSensitivity how to handle case sensitivity, null means case-sensitive - * @return a prefix checking filter - * @see PrefixFileFilter - * @since 2.0 - */ - public static IOFileFilter prefixFileFilter(final String prefix, final IOCase caseSensitivity) { - return new PrefixFileFilter(prefix, caseSensitivity); - } - - /** - * Returns a filter that returns true if the file name ends with the specified text. - * - * @param suffix the file name suffix - * @return a suffix checking filter - * @see SuffixFileFilter - */ - public static IOFileFilter suffixFileFilter(final String suffix) { - return new SuffixFileFilter(suffix); + public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber) { + return new MagicNumberFileFilter(magicNumber); } /** - * Returns a filter that returns true if the file name ends with the specified text. + * Returns a filter that accepts files that contains the provided magic + * number at a specified offset within the file. * - * @param suffix the file name suffix - * @param caseSensitivity how to handle case sensitivity, null means case-sensitive - * @return a suffix checking filter - * @see SuffixFileFilter - * @since 2.0 - */ - public static IOFileFilter suffixFileFilter(final String suffix, final IOCase caseSensitivity) { - return new SuffixFileFilter(suffix, caseSensitivity); - } - - /** - * Returns a filter that returns true if the file name matches the specified text. + * @param magicNumber the magic number (byte sequence) to match at the + * provided offset in each file. + * @param offset the offset within the files to look for the magic number. * - * @param name the file name - * @return a name checking filter - * @see NameFileFilter - */ - public static IOFileFilter nameFileFilter(final String name) { - return new NameFileFilter(name); - } - - /** - * Returns a filter that returns true if the file name matches the specified text. + * @return an IOFileFilter that accepts files containing the magic number + * at the specified offset. * - * @param name the file name - * @param caseSensitivity how to handle case sensitivity, null means case-sensitive - * @return a name checking filter - * @see NameFileFilter + * @throws IllegalArgumentException if <code>magicNumber</code> is + * {@code null}, or contains no bytes, or <code>offset</code> + * is a negative number. + * @see MagicNumberFileFilter * @since 2.0 */ - public static IOFileFilter nameFileFilter(final String name, final IOCase caseSensitivity) { - return new NameFileFilter(name, caseSensitivity); - } - - /** - * Returns a filter that checks if the file is a directory. - * - * @return file filter that accepts only directories and not files - * @see DirectoryFileFilter#DIRECTORY - */ - public static IOFileFilter directoryFileFilter() { - return DirectoryFileFilter.DIRECTORY; - } - - /** - * Returns a filter that checks if the file is a file (and not a directory). - * - * @return file filter that accepts only files and not directories - * @see FileFileFilter#FILE - */ - public static IOFileFilter fileFileFilter() { - return FileFileFilter.FILE; - } - - //----------------------------------------------------------------------- - /** - * Returns a filter that ANDs the two specified filters. - * - * @param filter1 the first filter - * @param filter2 the second filter - * @return a filter that ANDs the two specified filters - * @see #and(IOFileFilter...) - * @see AndFileFilter - * @deprecated use {@link #and(IOFileFilter...)} - */ - @Deprecated - public static IOFileFilter andFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) { - return new AndFileFilter(filter1, filter2); + public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber, final long offset) { + return new MagicNumberFileFilter(magicNumber, offset); } /** - * Returns a filter that ORs the two specified filters. + * Returns a filter that accepts files that begin with the provided magic + * number. * - * @param filter1 the first filter - * @param filter2 the second filter - * @return a filter that ORs the two specified filters - * @see #or(IOFileFilter...) - * @see OrFileFilter - * @deprecated use {@link #or(IOFileFilter...)} - */ - @Deprecated - public static IOFileFilter orFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) { - return new OrFileFilter(filter1, filter2); - } - - /** - * Returns a filter that ANDs the specified filters. + * @param magicNumber the magic number (byte sequence) to match at the + * beginning of each file. * - * @param filters the IOFileFilters that will be ANDed together. - * @return a filter that ANDs the specified filters + * @return an IOFileFilter that accepts files beginning with the provided + * magic number. * - * @throws IllegalArgumentException if the filters are null or contain a - * null value. - * @see AndFileFilter + * @throws IllegalArgumentException if <code>magicNumber</code> is + * {@code null} or the empty String. + * @see MagicNumberFileFilter * @since 2.0 */ - public static IOFileFilter and(final IOFileFilter... filters) { - return new AndFileFilter(toList(filters)); + public static IOFileFilter magicNumberFileFilter(final String magicNumber) { + return new MagicNumberFileFilter(magicNumber); } /** - * Returns a filter that ORs the specified filters. + * Returns a filter that accepts files that contains the provided magic + * number at a specified offset within the file. * - * @param filters the IOFileFilters that will be ORed together. - * @return a filter that ORs the specified filters + * @param magicNumber the magic number (byte sequence) to match at the + * provided offset in each file. + * @param offset the offset within the files to look for the magic number. * - * @throws IllegalArgumentException if the filters are null or contain a - * null value. - * @see OrFileFilter - * @since 2.0 - */ - public static IOFileFilter or(final IOFileFilter... filters) { - return new OrFileFilter(toList(filters)); - } - - /** - * Create a List of file filters. + * @return an IOFileFilter that accepts files containing the magic number + * at the specified offset. * - * @param filters The file filters - * @return The list of file filters - * @throws IllegalArgumentException if the filters are null or contain a - * null value. + * @throws IllegalArgumentException if <code>magicNumber</code> is + * {@code null} or the empty String, or if offset is a + * negative number. + * @see MagicNumberFileFilter * @since 2.0 */ - public static List<IOFileFilter> toList(final IOFileFilter... filters) { - if (filters == null) { - throw new IllegalArgumentException("The filters must not be null"); - } - final List<IOFileFilter> list = new ArrayList<>(filters.length); - for (int i = 0; i < filters.length; i++) { - if (filters[i] == null) { - throw new IllegalArgumentException("The filter[" + i + "] is null"); - } - list.add(filters[i]); - } - return list; + public static IOFileFilter magicNumberFileFilter(final String magicNumber, final long offset) { + return new MagicNumberFileFilter(magicNumber, offset); } /** - * Returns a filter that NOTs the specified filter. + * Decorates a filter to make it ignore CVS directories. + * Passing in {@code null} will return a filter that accepts everything + * except CVS directories. * - * @param filter the filter to invert - * @return a filter that NOTs the specified filter - * @see NotFileFilter + * @param filter the filter to decorate, null means an unrestricted filter + * @return the decorated filter, never null + * @since 1.1 (method existed but had bug in 1.0) */ - public static IOFileFilter notFileFilter(final IOFileFilter filter) { - return new NotFileFilter(filter); + public static IOFileFilter makeCVSAware(final IOFileFilter filter) { + return filter == null ? cvsFilter : and(filter, cvsFilter); } //----------------------------------------------------------------------- /** - * Returns a filter that always returns true. + * Decorates a filter so that it only applies to directories and not to files. * - * @return a true filter - * @see TrueFileFilter#TRUE + * @param filter the filter to decorate, null means an unrestricted filter + * @return the decorated filter, never null + * @see DirectoryFileFilter#DIRECTORY + * @since 1.3 */ - public static IOFileFilter trueFileFilter() { - return TrueFileFilter.TRUE; + public static IOFileFilter makeDirectoryOnly(final IOFileFilter filter) { + if (filter == null) { + return DirectoryFileFilter.DIRECTORY; + } + return new AndFileFilter(DirectoryFileFilter.DIRECTORY, filter); } /** - * Returns a filter that always returns false. + * Decorates a filter so that it only applies to files and not to directories. * - * @return a false filter - * @see FalseFileFilter#FALSE + * @param filter the filter to decorate, null means an unrestricted filter + * @return the decorated filter, never null + * @see FileFileFilter#FILE + * @since 1.3 */ - public static IOFileFilter falseFileFilter() { - return FalseFileFilter.FALSE; + public static IOFileFilter makeFileOnly(final IOFileFilter filter) { + if (filter == null) { + return FileFileFilter.FILE; + } + return new AndFileFilter(FileFileFilter.FILE, filter); } - //----------------------------------------------------------------------- /** - * Returns an <code>IOFileFilter</code> that wraps the - * <code>FileFilter</code> instance. + * Decorates a filter to make it ignore SVN directories. + * Passing in {@code null} will return a filter that accepts everything + * except SVN directories. * - * @param filter the filter to be wrapped - * @return a new filter that implements IOFileFilter - * @see DelegateFileFilter + * @param filter the filter to decorate, null means an unrestricted filter + * @return the decorated filter, never null + * @since 1.1 */ - public static IOFileFilter asFileFilter(final FileFilter filter) { - return new DelegateFileFilter(filter); + public static IOFileFilter makeSVNAware(final IOFileFilter filter) { + return filter == null ? svnFilter : and(filter, svnFilter); } /** - * Returns an <code>IOFileFilter</code> that wraps the - * <code>FilenameFilter</code> instance. + * Returns a filter that returns true if the file name matches the specified text. * - * @param filter the filter to be wrapped - * @return a new filter that implements IOFileFilter - * @see DelegateFileFilter + * @param name the file name + * @return a name checking filter + * @see NameFileFilter */ - public static IOFileFilter asFileFilter(final FilenameFilter filter) { - return new DelegateFileFilter(filter); + public static IOFileFilter nameFileFilter(final String name) { + return new NameFileFilter(name); } - //----------------------------------------------------------------------- /** - * Returns a filter that returns true if the file was last modified before - * or at the specified cutoff time. + * Returns a filter that returns true if the file name matches the specified text. * - * @param cutoff the time threshold - * @return an appropriately configured age file filter - * @see AgeFileFilter - * @since 1.2 + * @param name the file name + * @param caseSensitivity how to handle case sensitivity, null means case-sensitive + * @return a name checking filter + * @see NameFileFilter + * @since 2.0 */ - public static IOFileFilter ageFileFilter(final long cutoff) { - return new AgeFileFilter(cutoff); + public static IOFileFilter nameFileFilter(final String name, final IOCase caseSensitivity) { + return new NameFileFilter(name, caseSensitivity); } /** - * Returns a filter that filters files based on a cutoff time. + * Returns a filter that NOTs the specified filter. * - * @param cutoff the time threshold - * @param acceptOlder if true, older files get accepted, if false, newer - * @return an appropriately configured age file filter - * @see AgeFileFilter - * @since 1.2 + * @param filter the filter to invert + * @return a filter that NOTs the specified filter + * @see NotFileFilter */ - public static IOFileFilter ageFileFilter(final long cutoff, final boolean acceptOlder) { - return new AgeFileFilter(cutoff, acceptOlder); + public static IOFileFilter notFileFilter(final IOFileFilter filter) { + return new NotFileFilter(filter); } /** - * Returns a filter that returns true if the file was last modified before - * or at the specified cutoff date. + * Returns a filter that ORs the specified filters. * - * @param cutoffDate the time threshold - * @return an appropriately configured age file filter - * @see AgeFileFilter - * @since 1.2 + * @param filters the IOFileFilters that will be ORed together. + * @return a filter that ORs the specified filters + * + * @throws IllegalArgumentException if the filters are null or contain a + * null value. + * @see OrFileFilter + * @since 2.0 */ - public static IOFileFilter ageFileFilter(final Date cutoffDate) { - return new AgeFileFilter(cutoffDate); + public static IOFileFilter or(final IOFileFilter... filters) { + return new OrFileFilter(toList(filters)); } /** - * Returns a filter that filters files based on a cutoff date. + * Returns a filter that ORs the two specified filters. * - * @param cutoffDate the time threshold - * @param acceptOlder if true, older files get accepted, if false, newer - * @return an appropriately configured age file filter - * @see AgeFileFilter - * @since 1.2 + * @param filter1 the first filter + * @param filter2 the second filter + * @return a filter that ORs the two specified filters + * @see #or(IOFileFilter...) + * @see OrFileFilter + * @deprecated use {@link #or(IOFileFilter...)} */ - public static IOFileFilter ageFileFilter(final Date cutoffDate, final boolean acceptOlder) { - return new AgeFileFilter(cutoffDate, acceptOlder); + @Deprecated + public static IOFileFilter orFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) { + return new OrFileFilter(filter1, filter2); } /** - * Returns a filter that returns true if the file was last modified before - * or at the same time as the specified reference file. + * Returns a filter that returns true if the file name starts with the specified text. * - * @param cutoffReference the file whose last modification - * time is used as the threshold age of the files - * @return an appropriately configured age file filter - * @see AgeFileFilter - * @since 1.2 + * @param prefix the file name prefix + * @return a prefix checking filter + * @see PrefixFileFilter */ - public static IOFileFilter ageFileFilter(final File cutoffReference) { - return new AgeFileFilter(cutoffReference); + public static IOFileFilter prefixFileFilter(final String prefix) { + return new PrefixFileFilter(prefix); } /** - * Returns a filter that filters files based on a cutoff reference file. + * Returns a filter that returns true if the file name starts with the specified text. * - * @param cutoffReference the file whose last modification - * time is used as the threshold age of the files - * @param acceptOlder if true, older files get accepted, if false, newer - * @return an appropriately configured age file filter - * @see AgeFileFilter - * @since 1.2 + * @param prefix the file name prefix + * @param caseSensitivity how to handle case sensitivity, null means case-sensitive + * @return a prefix checking filter + * @see PrefixFileFilter + * @since 2.0 */ - public static IOFileFilter ageFileFilter(final File cutoffReference, final boolean acceptOlder) { - return new AgeFileFilter(cutoffReference, acceptOlder); + public static IOFileFilter prefixFileFilter(final String prefix, final IOCase caseSensitivity) { + return new PrefixFileFilter(prefix, caseSensitivity); } //----------------------------------------------------------------------- @@ -641,149 +723,67 @@ public class FileFilterUtils { } /** - * Returns a filter that accepts files that begin with the provided magic - * number. - * - * @param magicNumber the magic number (byte sequence) to match at the - * beginning of each file. - * - * @return an IOFileFilter that accepts files beginning with the provided - * magic number. - * - * @throws IllegalArgumentException if <code>magicNumber</code> is - * {@code null} or the empty String. - * @see MagicNumberFileFilter - * @since 2.0 - */ - public static IOFileFilter magicNumberFileFilter(final String magicNumber) { - return new MagicNumberFileFilter(magicNumber); - } - - /** - * Returns a filter that accepts files that contains the provided magic - * number at a specified offset within the file. - * - * @param magicNumber the magic number (byte sequence) to match at the - * provided offset in each file. - * @param offset the offset within the files to look for the magic number. - * - * @return an IOFileFilter that accepts files containing the magic number - * at the specified offset. + * Returns a filter that returns true if the file name ends with the specified text. * - * @throws IllegalArgumentException if <code>magicNumber</code> is - * {@code null} or the empty String, or if offset is a - * negative number. - * @see MagicNumberFileFilter - * @since 2.0 + * @param suffix the file name suffix + * @return a suffix checking filter + * @see SuffixFileFilter */ - public static IOFileFilter magicNumberFileFilter(final String magicNumber, final long offset) { - return new MagicNumberFileFilter(magicNumber, offset); + public static IOFileFilter suffixFileFilter(final String suffix) { + return new SuffixFileFilter(suffix); } /** - * Returns a filter that accepts files that begin with the provided magic - * number. - * - * @param magicNumber the magic number (byte sequence) to match at the - * beginning of each file. - * - * @return an IOFileFilter that accepts files beginning with the provided - * magic number. + * Returns a filter that returns true if the file name ends with the specified text. * - * @throws IllegalArgumentException if <code>magicNumber</code> is - * {@code null} or is of length zero. - * @see MagicNumberFileFilter + * @param suffix the file name suffix + * @param caseSensitivity how to handle case sensitivity, null means case-sensitive + * @return a suffix checking filter + * @see SuffixFileFilter * @since 2.0 */ - public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber) { - return new MagicNumberFileFilter(magicNumber); + public static IOFileFilter suffixFileFilter(final String suffix, final IOCase caseSensitivity) { + return new SuffixFileFilter(suffix, caseSensitivity); } /** - * Returns a filter that accepts files that contains the provided magic - * number at a specified offset within the file. - * - * @param magicNumber the magic number (byte sequence) to match at the - * provided offset in each file. - * @param offset the offset within the files to look for the magic number. - * - * @return an IOFileFilter that accepts files containing the magic number - * at the specified offset. + * Create a List of file filters. * - * @throws IllegalArgumentException if <code>magicNumber</code> is - * {@code null}, or contains no bytes, or <code>offset</code> - * is a negative number. - * @see MagicNumberFileFilter + * @param filters The file filters + * @return The list of file filters + * @throws IllegalArgumentException if the filters are null or contain a + * null value. * @since 2.0 */ - public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber, final long offset) { - return new MagicNumberFileFilter(magicNumber, offset); - } - - //----------------------------------------------------------------------- - /* Constructed on demand and then cached */ - private static final IOFileFilter cvsFilter = notFileFilter( - and(directoryFileFilter(), nameFileFilter("CVS"))); - - /* Constructed on demand and then cached */ - private static final IOFileFilter svnFilter = notFileFilter( - and(directoryFileFilter(), nameFileFilter(".svn"))); - - /** - * Decorates a filter to make it ignore CVS directories. - * Passing in {@code null} will return a filter that accepts everything - * except CVS directories. - * - * @param filter the filter to decorate, null means an unrestricted filter - * @return the decorated filter, never null - * @since 1.1 (method existed but had bug in 1.0) - */ - public static IOFileFilter makeCVSAware(final IOFileFilter filter) { - return filter == null ? cvsFilter : and(filter, cvsFilter); - } - - /** - * Decorates a filter to make it ignore SVN directories. - * Passing in {@code null} will return a filter that accepts everything - * except SVN directories. - * - * @param filter the filter to decorate, null means an unrestricted filter - * @return the decorated filter, never null - * @since 1.1 - */ - public static IOFileFilter makeSVNAware(final IOFileFilter filter) { - return filter == null ? svnFilter : and(filter, svnFilter); + public static List<IOFileFilter> toList(final IOFileFilter... filters) { + if (filters == null) { + throw new IllegalArgumentException("The filters must not be null"); + } + final List<IOFileFilter> list = new ArrayList<>(filters.length); + for (int i = 0; i < filters.length; i++) { + if (filters[i] == null) { + throw new IllegalArgumentException("The filter[" + i + "] is null"); + } + list.add(filters[i]); + } + return list; } //----------------------------------------------------------------------- /** - * Decorates a filter so that it only applies to directories and not to files. + * Returns a filter that always returns true. * - * @param filter the filter to decorate, null means an unrestricted filter - * @return the decorated filter, never null - * @see DirectoryFileFilter#DIRECTORY - * @since 1.3 + * @return a true filter + * @see TrueFileFilter#TRUE */ - public static IOFileFilter makeDirectoryOnly(final IOFileFilter filter) { - if (filter == null) { - return DirectoryFileFilter.DIRECTORY; - } - return new AndFileFilter(DirectoryFileFilter.DIRECTORY, filter); + public static IOFileFilter trueFileFilter() { + return TrueFileFilter.TRUE; } /** - * Decorates a filter so that it only applies to files and not to directories. - * - * @param filter the filter to decorate, null means an unrestricted filter - * @return the decorated filter, never null - * @see FileFileFilter#FILE - * @since 1.3 + * FileFilterUtils is not normally instantiated. */ - public static IOFileFilter makeFileOnly(final IOFileFilter filter) { - if (filter == null) { - return FileFileFilter.FILE; - } - return new AndFileFilter(FileFileFilter.FILE, filter); + public FileFilterUtils() { } } diff --git a/src/main/java/org/apache/commons/io/filefilter/HiddenFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/HiddenFileFilter.java index e4d1b19..2145274 100644 --- a/src/main/java/org/apache/commons/io/filefilter/HiddenFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/HiddenFileFilter.java @@ -50,11 +50,11 @@ import java.io.Serializable; */ public class HiddenFileFilter extends AbstractFileFilter implements Serializable { - private static final long serialVersionUID = 8930842316112759062L; - /** Singleton instance of <i>hidden</i> filter */ public static final IOFileFilter HIDDEN = new HiddenFileFilter(); + private static final long serialVersionUID = 8930842316112759062L; + /** Singleton instance of <i>visible</i> filter */ public static final IOFileFilter VISIBLE = new NotFileFilter(HIDDEN);