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.      * @throws IllegalArgumentException if the filters are null or contain a
  128.      *         null value.
  129.      * @see AndFileFilter
  130.      * @since 2.0
  131.      */
  132.     public static IOFileFilter and(final IOFileFilter... filters) {
  133.         return new AndFileFilter(toList(filters));
  134.     }

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

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

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

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

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

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

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

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

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

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

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

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

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

  389.     /**
  390.      * Returns a filter that accepts files that begin with the provided magic
  391.      * number.
  392.      *
  393.      * @param magicNumber the magic number (byte sequence) to match at the
  394.      *        beginning of each file.
  395.      *
  396.      * @return an IOFileFilter that accepts files beginning with the provided
  397.      *         magic number.
  398.      *
  399.      * @throws IllegalArgumentException if {@code magicNumber} is
  400.      *         {@code null} or is of length zero.
  401.      * @see MagicNumberFileFilter
  402.      * @since 2.0
  403.      */
  404.     public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber) {
  405.         return new MagicNumberFileFilter(magicNumber);
  406.     }

  407.     /**
  408.      * Returns a filter that accepts files that contains the provided magic
  409.      * number at a specified offset within the file.
  410.      *
  411.      * @param magicNumber the magic number (byte sequence) to match at the
  412.      *        provided offset in each file.
  413.      * @param offset the offset within the files to look for the magic number.
  414.      * @return an IOFileFilter that accepts files containing the magic number
  415.      *         at the specified offset.
  416.      *
  417.      * @throws IllegalArgumentException if {@code magicNumber} is
  418.      *         {@code null}, or contains no bytes, or {@code offset}
  419.      *         is a negative number.
  420.      * @see MagicNumberFileFilter
  421.      * @since 2.0
  422.      */
  423.     public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber, final long offset) {
  424.         return new MagicNumberFileFilter(magicNumber, offset);
  425.     }

  426.     /**
  427.      * Returns a filter that accepts files that begin with the provided magic
  428.      * number.
  429.      *
  430.      * @param magicNumber the magic number (byte sequence) to match at the
  431.      *        beginning of each file.
  432.      *
  433.      * @return an IOFileFilter that accepts files beginning with the provided
  434.      *         magic number.
  435.      *
  436.      * @throws IllegalArgumentException if {@code magicNumber} is
  437.      *         {@code null} or the empty String.
  438.      * @see MagicNumberFileFilter
  439.      * @since 2.0
  440.      */
  441.     public static IOFileFilter magicNumberFileFilter(final String magicNumber) {
  442.         return new MagicNumberFileFilter(magicNumber);
  443.     }

  444.     /**
  445.      * Returns a filter that accepts files that contains the provided magic
  446.      * number at a specified offset within the file.
  447.      *
  448.      * @param magicNumber the magic number (byte sequence) to match at the
  449.      *        provided offset in each file.
  450.      * @param offset the offset within the files to look for the magic number.
  451.      * @return an IOFileFilter that accepts files containing the magic number
  452.      *         at the specified offset.
  453.      *
  454.      * @throws IllegalArgumentException if {@code magicNumber} is
  455.      *         {@code null} or the empty String, or if offset is a
  456.      *         negative number.
  457.      * @see MagicNumberFileFilter
  458.      * @since 2.0
  459.      */
  460.     public static IOFileFilter magicNumberFileFilter(final String magicNumber, final long offset) {
  461.         return new MagicNumberFileFilter(magicNumber, offset);
  462.     }

  463.     /**
  464.      * Decorates a filter to make it ignore CVS directories.
  465.      * Passing in {@code null} will return a filter that accepts everything
  466.      * except CVS directories.
  467.      *
  468.      * @param filter  the filter to decorate, null means an unrestricted filter
  469.      * @return the decorated filter, never null
  470.      * @since 1.1 (method existed but had a bug in 1.0)
  471.      */
  472.     public static IOFileFilter makeCVSAware(final IOFileFilter filter) {
  473.         return filter == null ? CVS_FILTER : and(filter, CVS_FILTER);
  474.     }

  475.     /**
  476.      * Decorates a filter so that it only applies to directories and not to files.
  477.      *
  478.      * @param filter  the filter to decorate, null means an unrestricted filter
  479.      * @return the decorated filter, never null
  480.      * @see DirectoryFileFilter#DIRECTORY
  481.      * @since 1.3
  482.      */
  483.     public static IOFileFilter makeDirectoryOnly(final IOFileFilter filter) {
  484.         if (filter == null) {
  485.             return DirectoryFileFilter.DIRECTORY;
  486.         }
  487.         return DirectoryFileFilter.DIRECTORY.and(filter);
  488.     }

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

  503.     /**
  504.      * Decorates a filter to make it ignore SVN directories.
  505.      * Passing in {@code null} will return a filter that accepts everything
  506.      * except SVN directories.
  507.      *
  508.      * @param filter  the filter to decorate, null means an unrestricted filter
  509.      * @return the decorated filter, never null
  510.      * @since 1.1
  511.      */
  512.     public static IOFileFilter makeSVNAware(final IOFileFilter filter) {
  513.         return filter == null ? SVN_FILTER : and(filter, SVN_FILTER);
  514.     }

  515.     /**
  516.      * Returns a filter that returns true if the file name matches the specified text.
  517.      *
  518.      * @param name  the file name
  519.      * @return a name checking filter
  520.      * @see NameFileFilter
  521.      */
  522.     public static IOFileFilter nameFileFilter(final String name) {
  523.         return new NameFileFilter(name);
  524.     }

  525.     /**
  526.      * Returns a filter that returns true if the file name matches the specified text.
  527.      *
  528.      * @param name  the file name
  529.      * @param ioCase  how to handle case sensitivity, null means case-sensitive
  530.      * @return a name checking filter
  531.      * @see NameFileFilter
  532.      * @since 2.0
  533.      */
  534.     public static IOFileFilter nameFileFilter(final String name, final IOCase ioCase) {
  535.         return new NameFileFilter(name, ioCase);
  536.     }

  537.     /**
  538.      * Returns a filter that NOTs the specified filter.
  539.      *
  540.      * @param filter  the filter to invert
  541.      * @return a filter that NOTs the specified filter
  542.      * @see NotFileFilter
  543.      */
  544.     public static IOFileFilter notFileFilter(final IOFileFilter filter) {
  545.         return filter.negate();
  546.     }

  547.     /**
  548.      * Returns a filter that ORs the specified filters.
  549.      *
  550.      * @param filters the IOFileFilters that will be ORed together.
  551.      * @return a filter that ORs the specified filters
  552.      * @throws IllegalArgumentException if the filters are null or contain a
  553.      *         null value.
  554.      * @see OrFileFilter
  555.      * @since 2.0
  556.      */
  557.     public static IOFileFilter or(final IOFileFilter... filters) {
  558.         return new OrFileFilter(toList(filters));
  559.     }

  560.     /**
  561.      * Returns a filter that ORs the two specified filters.
  562.      *
  563.      * @param filter1  the first filter
  564.      * @param filter2  the second filter
  565.      * @return a filter that ORs the two specified filters
  566.      * @see #or(IOFileFilter...)
  567.      * @see OrFileFilter
  568.      * @deprecated use {@link #or(IOFileFilter...)}
  569.      */
  570.     @Deprecated
  571.     public static IOFileFilter orFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) {
  572.         return new OrFileFilter(filter1, filter2);
  573.     }

  574.     /**
  575.      * Returns a filter that returns true if the file name starts with the specified text.
  576.      *
  577.      * @param prefix  the file name prefix
  578.      * @return a prefix checking filter
  579.      * @see PrefixFileFilter
  580.      */
  581.     public static IOFileFilter prefixFileFilter(final String prefix) {
  582.         return new PrefixFileFilter(prefix);
  583.     }

  584.     /**
  585.      * Returns a filter that returns true if the file name starts with the specified text.
  586.      *
  587.      * @param prefix  the file name prefix
  588.      * @param ioCase  how to handle case sensitivity, null means case-sensitive
  589.      * @return a prefix checking filter
  590.      * @see PrefixFileFilter
  591.      * @since 2.0
  592.      */
  593.     public static IOFileFilter prefixFileFilter(final String prefix, final IOCase ioCase) {
  594.         return new PrefixFileFilter(prefix, ioCase);
  595.     }

  596.     /**
  597.      * Returns a filter that returns true if the file is bigger than a certain size.
  598.      *
  599.      * @param threshold  the file size threshold
  600.      * @return an appropriately configured SizeFileFilter
  601.      * @see SizeFileFilter
  602.      * @since 1.2
  603.      */
  604.     public static IOFileFilter sizeFileFilter(final long threshold) {
  605.         return new SizeFileFilter(threshold);
  606.     }

  607.     /**
  608.      * Returns a filter that filters based on file size.
  609.      *
  610.      * @param threshold  the file size threshold
  611.      * @param acceptLarger  if true, larger files get accepted, if false, smaller
  612.      * @return an appropriately configured SizeFileFilter
  613.      * @see SizeFileFilter
  614.      * @since 1.2
  615.      */
  616.     public static IOFileFilter sizeFileFilter(final long threshold, final boolean acceptLarger) {
  617.         return new SizeFileFilter(threshold, acceptLarger);
  618.     }

  619.     /**
  620.      * Returns a filter that accepts files whose size is &gt;= minimum size
  621.      * and &lt;= maximum size.
  622.      *
  623.      * @param minSizeInclusive the minimum file size (inclusive)
  624.      * @param maxSizeInclusive the maximum file size (inclusive)
  625.      * @return an appropriately configured IOFileFilter
  626.      * @see SizeFileFilter
  627.      * @since 1.3
  628.      */
  629.     public static IOFileFilter sizeRangeFileFilter(final long minSizeInclusive, final long maxSizeInclusive) {
  630.         final IOFileFilter minimumFilter = new SizeFileFilter(minSizeInclusive, true);
  631.         final IOFileFilter maximumFilter = new SizeFileFilter(maxSizeInclusive + 1L, false);
  632.         return minimumFilter.and(maximumFilter);
  633.     }

  634.     /**
  635.      * Returns a filter that returns true if the file name ends with the specified text.
  636.      *
  637.      * @param suffix  the file name suffix
  638.      * @return a suffix checking filter
  639.      * @see SuffixFileFilter
  640.      */
  641.     public static IOFileFilter suffixFileFilter(final String suffix) {
  642.         return new SuffixFileFilter(suffix);
  643.     }

  644.     /**
  645.      * Returns a filter that returns true if the file name ends with the specified text.
  646.      *
  647.      * @param suffix  the file name suffix
  648.      * @param ioCase  how to handle case sensitivity, null means case-sensitive
  649.      * @return a suffix checking filter
  650.      * @see SuffixFileFilter
  651.      * @since 2.0
  652.      */
  653.     public static IOFileFilter suffixFileFilter(final String suffix, final IOCase ioCase) {
  654.         return new SuffixFileFilter(suffix, ioCase);
  655.     }

  656.     /**
  657.      * Create a List of file filters.
  658.      *
  659.      * @param filters The file filters
  660.      * @return The list of file filters
  661.      * @throws NullPointerException if the filters are null or contain a
  662.      *         null value.
  663.      * @since 2.0
  664.      */
  665.     public static List<IOFileFilter> toList(final IOFileFilter... filters) {
  666.         return Stream.of(Objects.requireNonNull(filters, "filters")).map(Objects::requireNonNull).collect(Collectors.toList());
  667.     }

  668.     /**
  669.      * Returns a filter that always returns true.
  670.      *
  671.      * @return a true filter
  672.      * @see TrueFileFilter#TRUE
  673.      */
  674.     public static IOFileFilter trueFileFilter() {
  675.         return TrueFileFilter.TRUE;
  676.     }

  677.     /**
  678.      * FileFilterUtils is not normally instantiated.
  679.      */
  680.     public FileFilterUtils() {
  681.     }

  682. }