FileFilterUtils.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.io.filefilter;

  18. import java.io.File;
  19. import java.io.FileFilter;
  20. import java.io.FilenameFilter;
  21. import java.util.Arrays;
  22. import java.util.Collections;
  23. import java.util.Date;
  24. import java.util.HashSet;
  25. import java.util.List;
  26. import java.util.Objects;
  27. import java.util.Set;
  28. import java.util.stream.Collector;
  29. import java.util.stream.Collectors;
  30. import java.util.stream.Stream;
  31. import java.util.stream.StreamSupport;

  32. import org.apache.commons.io.FileUtils;
  33. import org.apache.commons.io.IOCase;

  34. /**
  35.  * Useful utilities for working with file filters. It provides access to most
  36.  * file filter implementations in this package so you don't have to import
  37.  * every class you use.
  38.  *
  39.  * @since 1.0
  40.  */
  41. public class FileFilterUtils {

  42.     /* Constructed on demand and then cached */
  43.     private static final IOFileFilter CVS_FILTER = notFileFilter(
  44.             and(directoryFileFilter(), nameFileFilter("CVS")));

  45.     /* Constructed on demand and then cached */
  46.     private static final IOFileFilter SVN_FILTER = notFileFilter(
  47.             and(directoryFileFilter(), nameFileFilter(".svn")));

  48.     /**
  49.      * Returns a filter that returns true if the file was last modified before
  50.      * or at the specified cutoff date.
  51.      *
  52.      * @param cutoffDate  the time threshold
  53.      * @return an appropriately configured age file filter
  54.      * @see AgeFileFilter
  55.      * @since 1.2
  56.      */
  57.     public static IOFileFilter ageFileFilter(final Date cutoffDate) {
  58.         return new AgeFileFilter(cutoffDate);
  59.     }

  60.     /**
  61.      * Returns a filter that filters files based on a cutoff date.
  62.      *
  63.      * @param cutoffDate  the time threshold
  64.      * @param acceptOlder  if true, older files get accepted, if false, newer
  65.      * @return an appropriately configured age file filter
  66.      * @see AgeFileFilter
  67.      * @since 1.2
  68.      */
  69.     public static IOFileFilter ageFileFilter(final Date cutoffDate, final boolean acceptOlder) {
  70.         return new AgeFileFilter(cutoffDate, acceptOlder);
  71.     }

  72.     /**
  73.      * Returns a filter that returns true if the file was last modified before
  74.      * or at the same time as the specified reference file.
  75.      *
  76.      * @param cutoffReference  the file whose last modification
  77.      *        time is used as the threshold age of the files
  78.      * @return an appropriately configured age file filter
  79.      * @see AgeFileFilter
  80.      * @since 1.2
  81.      */
  82.     public static IOFileFilter ageFileFilter(final File cutoffReference) {
  83.         return new AgeFileFilter(cutoffReference);
  84.     }

  85.     /**
  86.      * Returns a filter that filters files based on a cutoff reference file.
  87.      *
  88.      * @param cutoffReference  the file whose last modification
  89.      *        time is used as the threshold age of the files
  90.      * @param acceptOlder  if true, older files get accepted, if false, newer
  91.      * @return an appropriately configured age file filter
  92.      * @see AgeFileFilter
  93.      * @since 1.2
  94.      */
  95.     public static IOFileFilter ageFileFilter(final File cutoffReference, final boolean acceptOlder) {
  96.         return new AgeFileFilter(cutoffReference, acceptOlder);
  97.     }

  98.     /**
  99.      * Returns a filter that returns true if the file was last modified before
  100.      * or at the specified cutoff time.
  101.      *
  102.      * @param cutoffMillis  the time threshold
  103.      * @return an appropriately configured age file filter
  104.      * @see AgeFileFilter
  105.      * @since 1.2
  106.      */
  107.     public static IOFileFilter ageFileFilter(final long cutoffMillis) {
  108.         return new AgeFileFilter(cutoffMillis);
  109.     }

  110.     /**
  111.      * Returns a filter that filters files based on a cutoff time.
  112.      *
  113.      * @param cutoffMillis  the time threshold
  114.      * @param acceptOlder  if true, older files get accepted, if false, newer
  115.      * @return an appropriately configured age file filter
  116.      * @see AgeFileFilter
  117.      * @since 1.2
  118.      */
  119.     public static IOFileFilter ageFileFilter(final long cutoffMillis, final boolean acceptOlder) {
  120.         return new AgeFileFilter(cutoffMillis, acceptOlder);
  121.     }

  122.     /**
  123.      * Returns a filter that ANDs the specified filters.
  124.      *
  125.      * @param filters the IOFileFilters that will be ANDed together.
  126.      * @return a filter that ANDs the specified filters
  127.      *
  128.      * @throws IllegalArgumentException if the filters are null or contain a
  129.      *         null value.
  130.      * @see AndFileFilter
  131.      * @since 2.0
  132.      */
  133.     public static IOFileFilter and(final IOFileFilter... filters) {
  134.         return new AndFileFilter(toList(filters));
  135.     }

  136.     /**
  137.      * Returns a filter that ANDs the two specified filters.
  138.      *
  139.      * @param filter1  the first filter
  140.      * @param filter2  the second filter
  141.      * @return a filter that ANDs the two specified filters
  142.      * @see #and(IOFileFilter...)
  143.      * @see AndFileFilter
  144.      * @deprecated use {@link #and(IOFileFilter...)}
  145.      */
  146.     @Deprecated
  147.     public static IOFileFilter andFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) {
  148.         return new AndFileFilter(filter1, filter2);
  149.     }

  150.     /**
  151.      * Returns an {@link IOFileFilter} that wraps the
  152.      * {@link FileFilter} instance.
  153.      *
  154.      * @param filter  the filter to be wrapped
  155.      * @return a new filter that implements IOFileFilter
  156.      * @see DelegateFileFilter
  157.      */
  158.     public static IOFileFilter asFileFilter(final FileFilter filter) {
  159.         return new DelegateFileFilter(filter);
  160.     }

  161.     /**
  162.      * Returns an {@link IOFileFilter} that wraps the
  163.      * {@link FilenameFilter} instance.
  164.      *
  165.      * @param filter  the filter to be wrapped
  166.      * @return a new filter that implements IOFileFilter
  167.      * @see DelegateFileFilter
  168.      */
  169.     public static IOFileFilter asFileFilter(final FilenameFilter filter) {
  170.         return new DelegateFileFilter(filter);
  171.     }

  172.     /**
  173.      * Returns a filter that checks if the file is a directory.
  174.      *
  175.      * @return file filter that accepts only directories and not files
  176.      * @see DirectoryFileFilter#DIRECTORY
  177.      */
  178.     public static IOFileFilter directoryFileFilter() {
  179.         return DirectoryFileFilter.DIRECTORY;
  180.     }

  181.     /**
  182.      * Returns a filter that always returns false.
  183.      *
  184.      * @return a false filter
  185.      * @see FalseFileFilter#FALSE
  186.      */
  187.     public static IOFileFilter falseFileFilter() {
  188.         return FalseFileFilter.FALSE;
  189.     }

  190.     /**
  191.      * Returns a filter that checks if the file is a file (and not a directory).
  192.      *
  193.      * @return file filter that accepts only files and not directories
  194.      * @see FileFileFilter#INSTANCE
  195.      */
  196.     public static IOFileFilter fileFileFilter() {
  197.         return FileFileFilter.INSTANCE;
  198.     }

  199.     /**
  200.      * <p>
  201.      * Applies an {@link IOFileFilter} to the provided {@link File}
  202.      * objects. The resulting array is a subset of the original file list that
  203.      * matches the provided filter.
  204.      * </p>
  205.      *
  206.      * <pre>
  207.      * Set&lt;File&gt; allFiles = ...
  208.      * Set&lt;File&gt; javaFiles = FileFilterUtils.filterSet(allFiles,
  209.      *     FileFilterUtils.suffixFileFilter(".java"));
  210.      * </pre>
  211.      * @param filter the filter to apply to the set of files.
  212.      * @param files the array of files to apply the filter to.
  213.      *
  214.      * @return a subset of {@code files} that is accepted by the
  215.      *         file filter.
  216.      * @throws NullPointerException if the filter is {@code null}
  217.      *         or {@code files} contains a {@code null} value.
  218.      *
  219.      * @since 2.0
  220.      */
  221.     public static File[] filter(final IOFileFilter filter, final File... files) {
  222.         Objects.requireNonNull(filter, "filter");
  223.         if (files == null) {
  224.             return FileUtils.EMPTY_FILE_ARRAY;
  225.         }
  226.         return filterFiles(filter, Stream.of(files), Collectors.toList()).toArray(FileUtils.EMPTY_FILE_ARRAY);
  227.     }

  228.     /**
  229.      * <p>
  230.      * Applies an {@link IOFileFilter} to the provided {@link File}
  231.      * objects. The resulting array is a subset of the original file list that
  232.      * matches the provided filter.
  233.      * </p>
  234.      *
  235.      * <p>
  236.      * The {@link Set} returned by this method is not guaranteed to be thread safe.
  237.      * </p>
  238.      *
  239.      * <pre>
  240.      * Set&lt;File&gt; allFiles = ...
  241.      * Set&lt;File&gt; javaFiles = FileFilterUtils.filterSet(allFiles,
  242.      *     FileFilterUtils.suffixFileFilter(".java"));
  243.      * </pre>
  244.      * @param filter the filter to apply to the set of files.
  245.      * @param files the array of files to apply the filter to.
  246.      *
  247.      * @return a subset of {@code files} that is accepted by the
  248.      *         file filter.
  249.      * @throws IllegalArgumentException if the filter is {@code null}
  250.      *         or {@code files} contains a {@code null} value.
  251.      *
  252.      * @since 2.0
  253.      */
  254.     public static File[] filter(final IOFileFilter filter, final Iterable<File> files) {
  255.         return filterList(filter, files).toArray(FileUtils.EMPTY_FILE_ARRAY);
  256.     }

  257.     /**
  258.      * <p>
  259.      * Applies an {@link IOFileFilter} to the provided {@link File} stream and collects the accepted files.
  260.      * </p>
  261.      *
  262.      * @param filter the filter to apply to the stream of files.
  263.      * @param stream the stream of files on which to apply the filter.
  264.      * @param collector how to collect the end result.
  265.      *
  266.      * @param <R> the return type.
  267.      * @param <A> the mutable accumulation type of the reduction operation (often hidden as an implementation detail)
  268.      * @return a subset of files from the stream that is accepted by the filter.
  269.      * @throws NullPointerException if the filter is {@code null}.
  270.      */
  271.     private static <R, A> R filterFiles(final IOFileFilter filter, final Stream<File> stream,
  272.         final Collector<? super File, A, R> collector) {
  273.         Objects.requireNonNull(filter, "filter");
  274.         Objects.requireNonNull(collector, "collector");
  275.         if (stream == null) {
  276.             return Stream.<File>empty().collect(collector);
  277.         }
  278.         return stream.filter(filter::accept).collect(collector);
  279.     }

  280.     /**
  281.      * <p>
  282.      * Applies an {@link IOFileFilter} to the provided {@link File}
  283.      * objects. The resulting list is a subset of the original files that
  284.      * matches the provided filter.
  285.      * </p>
  286.      *
  287.      * <p>
  288.      * The {@link List} returned by this method is not guaranteed to be thread safe.
  289.      * </p>
  290.      *
  291.      * <pre>
  292.      * List&lt;File&gt; filesAndDirectories = ...
  293.      * List&lt;File&gt; directories = FileFilterUtils.filterList(filesAndDirectories,
  294.      *     FileFilterUtils.directoryFileFilter());
  295.      * </pre>
  296.      * @param filter the filter to apply to each files in the list.
  297.      * @param files the collection of files to apply the filter to.
  298.      *
  299.      * @return a subset of {@code files} that is accepted by the
  300.      *         file filter.
  301.      * @throws IllegalArgumentException if the filter is {@code null}
  302.      *         or {@code files} contains a {@code null} value.
  303.      * @since 2.0
  304.      */
  305.     public static List<File> filterList(final IOFileFilter filter, final File... files) {
  306.         return Arrays.asList(filter(filter, files));
  307.     }

  308.     /**
  309.      * <p>
  310.      * Applies an {@link IOFileFilter} to the provided {@link File}
  311.      * objects. The resulting list is a subset of the original files that
  312.      * matches the provided filter.
  313.      * </p>
  314.      *
  315.      * <p>
  316.      * The {@link List} returned by this method is not guaranteed to be thread safe.
  317.      * </p>
  318.      *
  319.      * <pre>
  320.      * List&lt;File&gt; filesAndDirectories = ...
  321.      * List&lt;File&gt; directories = FileFilterUtils.filterList(filesAndDirectories,
  322.      *     FileFilterUtils.directoryFileFilter());
  323.      * </pre>
  324.      * @param filter the filter to apply to each files in the list.
  325.      * @param files the collection of files to apply the filter to.
  326.      *
  327.      * @return a subset of {@code files} that is accepted by the
  328.      *         file filter.
  329.      * @throws IllegalArgumentException if the filter is {@code null}
  330.      * @since 2.0
  331.      */
  332.     public static List<File> filterList(final IOFileFilter filter, final Iterable<File> files) {
  333.         if (files == null) {
  334.             return Collections.emptyList();
  335.         }
  336.         return filterFiles(filter, StreamSupport.stream(files.spliterator(), false), Collectors.toList());
  337.     }

  338.     /**
  339.      * <p>
  340.      * Applies an {@link IOFileFilter} to the provided {@link File}
  341.      * objects. The resulting set is a subset of the original file list that
  342.      * matches the provided filter.
  343.      * </p>
  344.      *
  345.      * <p>
  346.      * The {@link Set} returned by this method is not guaranteed to be thread safe.
  347.      * </p>
  348.      *
  349.      * <pre>
  350.      * Set&lt;File&gt; allFiles = ...
  351.      * Set&lt;File&gt; javaFiles = FileFilterUtils.filterSet(allFiles,
  352.      *     FileFilterUtils.suffixFileFilter(".java"));
  353.      * </pre>
  354.      * @param filter the filter to apply to the set of files.
  355.      * @param files the collection of files to apply the filter to.
  356.      *
  357.      * @return a subset of {@code files} that is accepted by the
  358.      *         file filter.
  359.      * @throws IllegalArgumentException if the filter is {@code null}
  360.      *         or {@code files} contains a {@code null} value.
  361.      *
  362.      * @since 2.0
  363.      */
  364.     public static Set<File> filterSet(final IOFileFilter filter, final File... files) {
  365.         return new HashSet<>(Arrays.asList(filter(filter, files)));
  366.     }

  367.     /**
  368.      * <p>
  369.      * Applies an {@link IOFileFilter} to the provided {@link File}
  370.      * objects. The resulting set is a subset of the original file list that
  371.      * matches the provided filter.
  372.      * </p>
  373.      *
  374.      * <p>
  375.      * The {@link Set} returned by this method is not guaranteed to be thread safe.
  376.      * </p>
  377.      *
  378.      * <pre>
  379.      * Set&lt;File&gt; allFiles = ...
  380.      * Set&lt;File&gt; javaFiles = FileFilterUtils.filterSet(allFiles,
  381.      *     FileFilterUtils.suffixFileFilter(".java"));
  382.      * </pre>
  383.      * @param filter the filter to apply to the set of files.
  384.      * @param files the collection of files to apply the filter to.
  385.      *
  386.      * @return a subset of {@code files} that is accepted by the
  387.      *         file filter.
  388.      * @throws IllegalArgumentException if the filter is {@code null}
  389.      *
  390.      * @since 2.0
  391.      */
  392.     public static Set<File> filterSet(final IOFileFilter filter, final Iterable<File> files) {
  393.         if (files == null) {
  394.             return Collections.emptySet();
  395.         }
  396.         return filterFiles(filter, StreamSupport.stream(files.spliterator(), false), Collectors.toSet());
  397.     }

  398.     /**
  399.      * Returns a filter that accepts files that begin with the provided magic
  400.      * number.
  401.      *
  402.      * @param magicNumber the magic number (byte sequence) to match at the
  403.      *        beginning of each file.
  404.      *
  405.      * @return an IOFileFilter that accepts files beginning with the provided
  406.      *         magic number.
  407.      *
  408.      * @throws IllegalArgumentException if {@code magicNumber} is
  409.      *         {@code null} or is of length zero.
  410.      * @see MagicNumberFileFilter
  411.      * @since 2.0
  412.      */
  413.     public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber) {
  414.         return new MagicNumberFileFilter(magicNumber);
  415.     }

  416.     /**
  417.      * Returns a filter that accepts files that contains the provided magic
  418.      * number at a specified offset within the file.
  419.      *
  420.      * @param magicNumber the magic number (byte sequence) to match at the
  421.      *        provided offset in each file.
  422.      * @param offset the offset within the files to look for the magic number.
  423.      *
  424.      * @return an IOFileFilter that accepts files containing the magic number
  425.      *         at the specified offset.
  426.      *
  427.      * @throws IllegalArgumentException if {@code magicNumber} is
  428.      *         {@code null}, or contains no bytes, or {@code offset}
  429.      *         is a negative number.
  430.      * @see MagicNumberFileFilter
  431.      * @since 2.0
  432.      */
  433.     public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber, final long offset) {
  434.         return new MagicNumberFileFilter(magicNumber, offset);
  435.     }

  436.     /**
  437.      * Returns a filter that accepts files that begin with the provided magic
  438.      * number.
  439.      *
  440.      * @param magicNumber the magic number (byte sequence) to match at the
  441.      *        beginning of each file.
  442.      *
  443.      * @return an IOFileFilter that accepts files beginning with the provided
  444.      *         magic number.
  445.      *
  446.      * @throws IllegalArgumentException if {@code magicNumber} is
  447.      *         {@code null} or the empty String.
  448.      * @see MagicNumberFileFilter
  449.      * @since 2.0
  450.      */
  451.     public static IOFileFilter magicNumberFileFilter(final String magicNumber) {
  452.         return new MagicNumberFileFilter(magicNumber);
  453.     }

  454.     /**
  455.      * Returns a filter that accepts files that contains the provided magic
  456.      * number at a specified offset within the file.
  457.      *
  458.      * @param magicNumber the magic number (byte sequence) to match at the
  459.      *        provided offset in each file.
  460.      * @param offset the offset within the files to look for the magic number.
  461.      *
  462.      * @return an IOFileFilter that accepts files containing the magic number
  463.      *         at the specified offset.
  464.      *
  465.      * @throws IllegalArgumentException if {@code magicNumber} is
  466.      *         {@code null} or the empty String, or if offset is a
  467.      *         negative number.
  468.      * @see MagicNumberFileFilter
  469.      * @since 2.0
  470.      */
  471.     public static IOFileFilter magicNumberFileFilter(final String magicNumber, final long offset) {
  472.         return new MagicNumberFileFilter(magicNumber, offset);
  473.     }

  474.     /**
  475.      * Decorates a filter to make it ignore CVS directories.
  476.      * Passing in {@code null} will return a filter that accepts everything
  477.      * except CVS directories.
  478.      *
  479.      * @param filter  the filter to decorate, null means an unrestricted filter
  480.      * @return the decorated filter, never null
  481.      * @since 1.1 (method existed but had a bug in 1.0)
  482.      */
  483.     public static IOFileFilter makeCVSAware(final IOFileFilter filter) {
  484.         return filter == null ? CVS_FILTER : and(filter, CVS_FILTER);
  485.     }

  486.     /**
  487.      * Decorates a filter so that it only applies to directories and not to files.
  488.      *
  489.      * @param filter  the filter to decorate, null means an unrestricted filter
  490.      * @return the decorated filter, never null
  491.      * @see DirectoryFileFilter#DIRECTORY
  492.      * @since 1.3
  493.      */
  494.     public static IOFileFilter makeDirectoryOnly(final IOFileFilter filter) {
  495.         if (filter == null) {
  496.             return DirectoryFileFilter.DIRECTORY;
  497.         }
  498.         return DirectoryFileFilter.DIRECTORY.and(filter);
  499.     }

  500.     /**
  501.      * Decorates a filter so that it only applies to files and not to directories.
  502.      *
  503.      * @param filter  the filter to decorate, null means an unrestricted filter
  504.      * @return the decorated filter, never null
  505.      * @see FileFileFilter#INSTANCE
  506.      * @since 1.3
  507.      */
  508.     public static IOFileFilter makeFileOnly(final IOFileFilter filter) {
  509.         if (filter == null) {
  510.             return FileFileFilter.INSTANCE;
  511.         }
  512.         return FileFileFilter.INSTANCE.and(filter);
  513.     }

  514.     /**
  515.      * Decorates a filter to make it ignore SVN directories.
  516.      * Passing in {@code null} will return a filter that accepts everything
  517.      * except SVN directories.
  518.      *
  519.      * @param filter  the filter to decorate, null means an unrestricted filter
  520.      * @return the decorated filter, never null
  521.      * @since 1.1
  522.      */
  523.     public static IOFileFilter makeSVNAware(final IOFileFilter filter) {
  524.         return filter == null ? SVN_FILTER : and(filter, SVN_FILTER);
  525.     }

  526.     /**
  527.      * Returns a filter that returns true if the file name matches the specified text.
  528.      *
  529.      * @param name  the file name
  530.      * @return a name checking filter
  531.      * @see NameFileFilter
  532.      */
  533.     public static IOFileFilter nameFileFilter(final String name) {
  534.         return new NameFileFilter(name);
  535.     }

  536.     /**
  537.      * Returns a filter that returns true if the file name matches the specified text.
  538.      *
  539.      * @param name  the file name
  540.      * @param ioCase  how to handle case sensitivity, null means case-sensitive
  541.      * @return a name checking filter
  542.      * @see NameFileFilter
  543.      * @since 2.0
  544.      */
  545.     public static IOFileFilter nameFileFilter(final String name, final IOCase ioCase) {
  546.         return new NameFileFilter(name, ioCase);
  547.     }

  548.     /**
  549.      * Returns a filter that NOTs the specified filter.
  550.      *
  551.      * @param filter  the filter to invert
  552.      * @return a filter that NOTs the specified filter
  553.      * @see NotFileFilter
  554.      */
  555.     public static IOFileFilter notFileFilter(final IOFileFilter filter) {
  556.         return filter.negate();
  557.     }

  558.     /**
  559.      * Returns a filter that ORs the specified filters.
  560.      *
  561.      * @param filters the IOFileFilters that will be ORed together.
  562.      * @return a filter that ORs the specified filters
  563.      *
  564.      * @throws IllegalArgumentException if the filters are null or contain a
  565.      *         null value.
  566.      * @see OrFileFilter
  567.      * @since 2.0
  568.      */
  569.     public static IOFileFilter or(final IOFileFilter... filters) {
  570.         return new OrFileFilter(toList(filters));
  571.     }

  572.     /**
  573.      * Returns a filter that ORs the two specified filters.
  574.      *
  575.      * @param filter1  the first filter
  576.      * @param filter2  the second filter
  577.      * @return a filter that ORs the two specified filters
  578.      * @see #or(IOFileFilter...)
  579.      * @see OrFileFilter
  580.      * @deprecated use {@link #or(IOFileFilter...)}
  581.      */
  582.     @Deprecated
  583.     public static IOFileFilter orFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) {
  584.         return new OrFileFilter(filter1, filter2);
  585.     }

  586.     /**
  587.      * Returns a filter that returns true if the file name starts with the specified text.
  588.      *
  589.      * @param prefix  the file name prefix
  590.      * @return a prefix checking filter
  591.      * @see PrefixFileFilter
  592.      */
  593.     public static IOFileFilter prefixFileFilter(final String prefix) {
  594.         return new PrefixFileFilter(prefix);
  595.     }

  596.     /**
  597.      * Returns a filter that returns true if the file name starts with the specified text.
  598.      *
  599.      * @param prefix  the file name prefix
  600.      * @param ioCase  how to handle case sensitivity, null means case-sensitive
  601.      * @return a prefix checking filter
  602.      * @see PrefixFileFilter
  603.      * @since 2.0
  604.      */
  605.     public static IOFileFilter prefixFileFilter(final String prefix, final IOCase ioCase) {
  606.         return new PrefixFileFilter(prefix, ioCase);
  607.     }

  608.     /**
  609.      * Returns a filter that returns true if the file is bigger than a certain size.
  610.      *
  611.      * @param threshold  the file size threshold
  612.      * @return an appropriately configured SizeFileFilter
  613.      * @see SizeFileFilter
  614.      * @since 1.2
  615.      */
  616.     public static IOFileFilter sizeFileFilter(final long threshold) {
  617.         return new SizeFileFilter(threshold);
  618.     }

  619.     /**
  620.      * Returns a filter that filters based on file size.
  621.      *
  622.      * @param threshold  the file size threshold
  623.      * @param acceptLarger  if true, larger files get accepted, if false, smaller
  624.      * @return an appropriately configured SizeFileFilter
  625.      * @see SizeFileFilter
  626.      * @since 1.2
  627.      */
  628.     public static IOFileFilter sizeFileFilter(final long threshold, final boolean acceptLarger) {
  629.         return new SizeFileFilter(threshold, acceptLarger);
  630.     }

  631.     /**
  632.      * Returns a filter that accepts files whose size is &gt;= minimum size
  633.      * and &lt;= maximum size.
  634.      *
  635.      * @param minSizeInclusive the minimum file size (inclusive)
  636.      * @param maxSizeInclusive the maximum file size (inclusive)
  637.      * @return an appropriately configured IOFileFilter
  638.      * @see SizeFileFilter
  639.      * @since 1.3
  640.      */
  641.     public static IOFileFilter sizeRangeFileFilter(final long minSizeInclusive, final long maxSizeInclusive ) {
  642.         final IOFileFilter minimumFilter = new SizeFileFilter(minSizeInclusive, true);
  643.         final IOFileFilter maximumFilter = new SizeFileFilter(maxSizeInclusive + 1L, false);
  644.         return minimumFilter.and(maximumFilter);
  645.     }

  646.     /**
  647.      * Returns a filter that returns true if the file name ends with the specified text.
  648.      *
  649.      * @param suffix  the file name suffix
  650.      * @return a suffix checking filter
  651.      * @see SuffixFileFilter
  652.      */
  653.     public static IOFileFilter suffixFileFilter(final String suffix) {
  654.         return new SuffixFileFilter(suffix);
  655.     }

  656.     /**
  657.      * Returns a filter that returns true if the file name ends with the specified text.
  658.      *
  659.      * @param suffix  the file name suffix
  660.      * @param ioCase  how to handle case sensitivity, null means case-sensitive
  661.      * @return a suffix checking filter
  662.      * @see SuffixFileFilter
  663.      * @since 2.0
  664.      */
  665.     public static IOFileFilter suffixFileFilter(final String suffix, final IOCase ioCase) {
  666.         return new SuffixFileFilter(suffix, ioCase);
  667.     }

  668.     /**
  669.      * Create a List of file filters.
  670.      *
  671.      * @param filters The file filters
  672.      * @return The list of file filters
  673.      * @throws NullPointerException if the filters are null or contain a
  674.      *         null value.
  675.      * @since 2.0
  676.      */
  677.     public static List<IOFileFilter> toList(final IOFileFilter... filters) {
  678.         return Stream.of(Objects.requireNonNull(filters, "filters")).map(Objects::requireNonNull).collect(Collectors.toList());
  679.     }

  680.     /**
  681.      * Returns a filter that always returns true.
  682.      *
  683.      * @return a true filter
  684.      * @see TrueFileFilter#TRUE
  685.      */
  686.     public static IOFileFilter trueFileFilter() {
  687.         return TrueFileFilter.TRUE;
  688.     }

  689.     /**
  690.      * FileFilterUtils is not normally instantiated.
  691.      */
  692.     public FileFilterUtils() {
  693.     }

  694. }