Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 16 package org.apache.commons.io.filefilter; 17 18 import java.io.File ; 19 import java.util.List ; 20 21 44 public class PrefixFileFilter extends AbstractFileFilter { 45 46 47 private String [] prefixes; 48 49 55 public PrefixFileFilter(String prefix) { 56 if (prefix == null) { 57 throw new IllegalArgumentException ("The prefix must not be null"); 58 } 59 this.prefixes = new String [] {prefix}; 60 } 61 62 71 public PrefixFileFilter(String [] prefixes) { 72 if (prefixes == null) { 73 throw new IllegalArgumentException ("The array of prefixes must not be null"); 74 } 75 this.prefixes = prefixes; 76 } 77 78 85 public PrefixFileFilter(List prefixes) { 86 if (prefixes == null) { 87 throw new IllegalArgumentException ("The list of prefixes must not be null"); 88 } 89 this.prefixes = (String []) prefixes.toArray(new String [prefixes.size()]); 90 } 91 92 98 public boolean accept(File file) { 99 String name = file.getName(); 100 for (int i = 0; i < this.prefixes.length; i++) { 101 if (name.startsWith(this.prefixes[i])) { 102 return true; 103 } 104 } 105 return false; 106 } 107 108 115 public boolean accept(File file, String name) { 116 for (int i = 0; i < prefixes.length; i++) { 117 if (name.startsWith(prefixes[i])) { 118 return true; 119 } 120 } 121 return false; 122 } 123 124 } 125
| Popular Tags
|