(追記) (追記ここまで)

Filter : Java Glossary

home page go to the Java Glossary Home go to the Computer Buyer’s Glossary up jump to foot of page Google search web for more information on this topic Pinterest pin button
*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)
©1996-2017 2007年08月03日 Roedy Green of Canadian Mind Products

Filter
The term has several meanings:
  • A filter lets you display a list of files with some of the files filtered out. If works with File. list and FilnameFilter.
  • File.list just gives you the unqualified filename. If you want a filtered list of File OBjects containing the full path, you use File. listFiles and a FilenameFilter alternatively a FilenameFilter .
  • If you are selecting files to display in Swing with a JFilechooser and want to filter our various files from consideration, the classes of interest are: javax.swing.filechooser. FileFilter, javax.swing. JFileChooser, javax.swing.plaf. BasicFileChooserUI, javax.swing.plaf.multi.MultiFileChooserUI.
  • In the context of Servlets, javax.servlet. Filter is an interface to allow a transaction to be processed in an assembly line. Each Filter does some of the work and passes on the input or output to the next filter in the chain and decides on who is next.
  • There are pair classes you can override to intervene on the processing of an I/O stream to modify it, collect statistics or monitor progress. You override FilterInputStream or FilterOutputStream and insert than in the chain of processors in the same way you insert BufferedInputStream.

Filtering File.list

You filter File.list by writing a class that implements java.io. FilenameFilter;
String[] filenames = file.list( someFilter );
will get list of files in this directory. Wildcards won’t work. Note it returns an array of Strings, not including the directory, not File objects. Files are not in any particular order. They include the subdirectories, but not the . or .. entries.

Your FilenameFilter needs at a minimum to filter with File.isDirectory().

You can also use FileDialog.setFilenameFilter( java.io.FilenameFilter ) to restrict which files are displayed in a File choosing dialog.

Here is how to write a simple class that implements the FilenameFilter interface:

[フレーム] I have written 10 FilenameFilters with source. All are trivial except for the MultiFilter that lets you combine other filters in various ways.

They come with Java source. The collection is mainly for newbies trying to get some ideas on how FilenameFilters work and how you could write them.

FilenameFilters
Name Purpose
AllDirectoriesFilter gets all directories
AllFilesFilter gets all files
ClamFilter simple wildcard
DirListFilter gets a list of directories
EndsWithFilter gets files whose names end with a given string.
ExtensionFilter gets files matching a list of extensions
EverythingFilter gets everything
FileLengthFilter gets short or long files
FilenameLengthFilter gets short or long filenames
FileListFilter gets a list of files
MultiFilter combines other Filters with consider, must and never.
RecentFilter filters based on lastModified date
RegexFilter filters with Regex expressions.
StartsWithFilter gets files whose names start with a given string.

You can cascade (combine) FilenameFilters by having one ask advice of another, or write a mother filter that asks the advice of several child filters and && or || the results of their accept methods. MultiFilter makes that task easy.

FileInputStream

Here is rough example how you might use a FileInputStream to monitor progress. You could write yours simply by overriding reportProgress in mine. [フレーム]

Learning More

Oracle’s Javadoc on FilenameFilter class : available:
Oracle’s Javadoc on FileFilter class : available:
Oracle’s Javadoc on File class : available:
Oracle’s Javadoc on FilterInputStream class : available:
Oracle’s Javadoc on FilterOutputStream class : available:

standard footer
CMP home jump to top

This page is posted
on the web at:

http://mindprod.com/jgloss/filter.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\filter.html
Canadian Mind Products
Please read the feedback from other visitors, or send your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.
Canadian Mind Products
IP:[65.110.21.43]
Your face IP:[40.74.122.252]
(追記) (追記ここまで)
Feedback You are visitor number
website statistics
[フレーム]

AltStyle によって変換されたページ (->オリジナル) /