NIO2 API

org.classpath.icedtea.java.nio.file
Class DirectoryStreamFilters

java.lang.Object
  extended by org.classpath.icedtea.java.nio.file.DirectoryStreamFilters

public final class DirectoryStreamFilters
extends Object

This class consists exclusively of static methods that construct or combine filters.

Since:
1.7

Method Summary
static
<T> DirectoryStream.Filter<T>
allOf(Iterable<? extends DirectoryStream.Filter<? super T>> filters)
          Returns a directory stream filter that accepts a directory entry if the entry is accepted by all of the given filters.
static
<T> DirectoryStream.Filter<T>
anyOf(Iterable<? extends DirectoryStream.Filter<? super T>> filters)
          Returns a directory stream filter that accepts a directory entry if the entry is accepted by one or more of the given filters.
static
<T> DirectoryStream.Filter<T>
complementOf(DirectoryStream.Filter<T> filter)
          Returns a directory stream filter that is the complement of the given filter.
static
<T extends FileRef>
DirectoryStream.Filter<T>
newContentTypeFilter(String type)
          Constructs a directory stream filter that filters directory entries by their MIME content type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newContentTypeFilter

public static <T extends FileRef> DirectoryStream.Filter<T> newContentTypeFilter(String type)
Constructs a directory stream filter that filters directory entries by their MIME content type. The directory stream filter's accept method returns true if the content type of the directory entry can be determined by invoking the probeContentType method, and the content type matches the given content type.

The type parameter is the value of a Multipurpose Internet Mail Extension (MIME) content type as defined by RFC 2045: Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies. It is parsable according to the grammar in the RFC. Any space characters ('\u0020') surrounding its components are ignored. The type parameter is parsed into its primary and subtype components which are used to match the primary and subtype components of each directory entry's content type. Parameters are not allowed. The primary type matches if it has value '*' or is equal to the primary type of the directory entry's content type without regard to case. The subtype matches if has the value '*' or is equal to the subtype of the directory entry's content type without regard to case. If both the primary and subtype match then the filter's accept method returns true. If the content type of a directory entry cannot be determined then the entry is filtered.

The accept method of the resulting directory stream filter throws IOError if the probing of the content type fails by throwing an IOException. Security exceptions are also propogated to the caller of the accept method.

Usage Example: Suppose we require to list only the HTML files in a directory.

     DirectoryStream.Filter<FileRef> filter =
         DirectoryStreamFilters.newContentTypeFilter("text/html");
 

Parameters:
type - The content type
Returns:
A new directory stream filter
Throws:
IllegalArgumentException - If the type parameter cannot be parsed as a MIME type or it has parameters

allOf

public static <T> DirectoryStream.Filter<T> allOf(Iterable<? extends DirectoryStream.Filter<? super T>> filters)
Returns a directory stream filter that accepts a directory entry if the entry is accepted by all of the given filters.

This method returns a filter that invokes, in iterator order, the accept method of each of the filters. If false is returned by any of the filters then the directory entry is filtered. If the directory entry is not filtered then the resulting filter accepts the entry. If the iterator returns zero elements then the resulting filter accepts all directory entries.

Usage Example:

     List<DirectoryStream.Filter<? super Path>> filters = ...
     DirectoryStream.Filter<Path> filter = DirectoryStreamFilters.allOf(filters);
 

Parameters:
filters - The sequence of filters
Returns:
The resulting filter

anyOf

public static <T> DirectoryStream.Filter<T> anyOf(Iterable<? extends DirectoryStream.Filter<? super T>> filters)
Returns a directory stream filter that accepts a directory entry if the entry is accepted by one or more of the given filters.

This method returns a filter that invokes, in iteration order, the accept method of each of filter. If true is returned by any of the filters then the directory entry is accepted. If none of the filters accepts the directory entry then it is filtered. If the iterator returns zero elements then the resulting filter filters all directory entries.

Parameters:
filters - The sequence of filters
Returns:
The resulting filter

complementOf

public static <T> DirectoryStream.Filter<T> complementOf(DirectoryStream.Filter<T> filter)
Returns a directory stream filter that is the complement of the given filter. The resulting filter accepts a directory entry if filtered by the given filter, and filters any entries that are accepted by the given filter.

Parameters:
filter - The given filter
Returns:
The resulting filter that is the complement of the given filter

NIO2 API

Copyright © 2007, 2011, Oracle and/or its affiliates. All rights reserved.