diff options
Diffstat (limited to 'NET/worlds/scape/FileList.java')
| -rw-r--r-- | NET/worlds/scape/FileList.java | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/NET/worlds/scape/FileList.java b/NET/worlds/scape/FileList.java new file mode 100644 index 0000000..6764f78 --- /dev/null +++ b/NET/worlds/scape/FileList.java @@ -0,0 +1,144 @@ +/* */ package NET.worlds.scape; +/* */ +/* */ import java.io.File; +/* */ import java.io.FilenameFilter; +/* */ import java.util.Enumeration; +/* */ import java.util.StringTokenizer; +/* */ import java.util.Vector; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class FileList +/* */ implements FilenameFilter +/* */ { +/* */ private String dirList; +/* */ private String extList; +/* */ private Vector<String> exts; +/* */ private boolean keepPathInfo; +/* 25 */ private boolean sort = true; +/* */ +/* */ public FileList(String dirList, String extList) +/* */ { +/* 29 */ this.dirList = dirList; +/* 30 */ this.extList = extList; +/* */ } +/* */ +/* */ public String getExtList() { +/* 34 */ return this.extList; +/* */ } +/* */ +/* */ private static Vector<String> breakUp(String list) { +/* 38 */ StringTokenizer t = new StringTokenizer(list, File.pathSeparator, false); +/* 39 */ Vector<String> v = new Vector(); +/* 40 */ while (t.hasMoreTokens()) +/* 41 */ v.addElement(t.nextToken()); +/* 42 */ return v; +/* */ } +/* */ +/* */ public boolean accept(File dir, String name) { +/* 46 */ return extMatches(name, this.exts); +/* */ } +/* */ +/* */ public static boolean extMatches(String name, Vector<String> exts) +/* */ { +/* 51 */ int index = name.lastIndexOf("."); +/* 52 */ if (index != -1) { +/* 53 */ String ext = name.substring(index + 1); +/* 54 */ Enumeration<String> e = exts.elements(); +/* 55 */ while (e.hasMoreElements()) +/* 56 */ if (ext.equalsIgnoreCase((String)e.nextElement())) +/* 57 */ return true; +/* */ } +/* 59 */ return false; +/* */ } +/* */ +/* */ public static boolean extMatches(String name, String exts) { +/* 63 */ return extMatches(name, breakUp(exts)); +/* */ } +/* */ +/* */ public boolean extMatches(String name) +/* */ { +/* 68 */ return extMatches(name, this.extList); +/* */ } +/* */ +/* */ public FileList keepPathInfo() { +/* 72 */ this.keepPathInfo = true; +/* 73 */ return this; +/* */ } +/* */ +/* */ public FileList dontSort() { +/* 77 */ this.sort = false; +/* 78 */ return this; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public static String removeTrailingSlash(String dir) +/* */ { +/* 86 */ if (dir != null) { +/* 87 */ int len = dir.length(); +/* 88 */ if (len > 0) { +/* 89 */ char c = dir.charAt(len - 1); +/* 90 */ if ((c == '/') || (c == '\\')) { +/* 91 */ dir = dir.substring(0, len - 1); +/* */ } +/* */ } +/* */ } +/* 95 */ return dir; +/* */ } +/* */ +/* */ public Vector<String> getList() +/* */ { +/* 100 */ this.exts = breakUp(this.extList); +/* 101 */ Vector<String> dirs = breakUp(this.dirList); +/* */ +/* */ +/* 104 */ Vector<String> v = new Vector(); +/* 105 */ Enumeration<String> edirs = dirs.elements(); +/* 106 */ while (edirs.hasMoreElements()) { +/* 107 */ String dir = removeTrailingSlash((String)edirs.nextElement()); +/* */ +/* 109 */ File f = new File(dir); +/* 110 */ if (f.exists()) { +/* 111 */ String[] list = f.list(this); +/* 112 */ if ((this.keepPathInfo) && (!dir.equals("."))) { +/* 113 */ dir = dir + File.separator; +/* */ } else +/* 115 */ dir = ""; +/* 116 */ for (int i = 0; i < list.length; i++) { +/* 117 */ String name = dir + list[i]; +/* 118 */ if (this.sort) { +/* 119 */ int count = v.size(); +/* */ +/* 121 */ String lname = name.toLowerCase(); +/* 122 */ for (int j = 0; j < count; j++) { +/* 123 */ if (lname.compareTo(((String)v.elementAt(j)) +/* 124 */ .toLowerCase()) < 0) { +/* 125 */ v.insertElementAt(name, j); +/* 126 */ break; +/* */ } +/* */ } +/* 129 */ if (j == count) +/* 130 */ v.addElement(name); +/* */ } else { +/* 132 */ v.addElement(name); +/* */ } +/* */ } +/* */ } } +/* 136 */ return v; +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\FileList.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |