1 22 package org.jboss.util.file; 23 24 import java.io.File ; 25 import java.io.FileFilter ; 26 27 33 public class FileSuffixFilter 34 implements FileFilter 35 { 36 37 protected final String suffixes[]; 38 39 40 protected final boolean ignoreCase; 41 42 48 public FileSuffixFilter(final String suffixes[], 49 final boolean ignoreCase) 50 { 51 this.ignoreCase = ignoreCase; 52 if (ignoreCase) { 53 this.suffixes = new String [suffixes.length]; 54 for (int i=0; i<suffixes.length; i++) { 55 this.suffixes[i] = suffixes[i].toLowerCase(); 56 } 57 } 58 else { 59 this.suffixes = suffixes; 60 } 61 } 62 63 68 public FileSuffixFilter(final String suffixes[]) 69 { 70 this(suffixes, false); 71 } 72 73 79 public FileSuffixFilter(final String suffix, 80 final boolean ignoreCase) 81 { 82 this(new String [] { suffix }, ignoreCase); 83 } 84 85 90 public FileSuffixFilter(final String suffix) { 91 this(suffix, false); 92 } 93 94 100 public boolean accept(final File file) { 101 boolean success = false; 102 103 for (int i=0; i<suffixes.length && !success; i++) { 104 if (ignoreCase) 105 success = file.getName().toLowerCase().endsWith(suffixes[i]); 106 else 107 success = file.getName().endsWith(suffixes[i]); 108 } 109 110 return success; 111 } 112 } 113 | Popular Tags |