1 26 package org.objectweb.petals.classloader.locator; 27 28 import java.io.File ; 29 import java.io.IOException ; 30 import java.net.URL ; 31 import java.util.ArrayList ; 32 import java.util.List ; 33 34 40 public class DirLocator extends Locator { 41 42 45 private File file = null; 46 47 54 public DirLocator(URL jar) throws IOException { 55 String filename = jar.getFile(); 56 file = new File (filename); 57 if (!file.exists()) { 58 throw new IOException ("File " + file + " does not exists."); 59 } 60 if (!file.isDirectory()) { 61 throw new IOException ("File " + file + " is not a directory."); 62 } 63 } 64 65 72 public boolean hasFile(String path) { 73 74 File child = new File (file, path); 75 return (child.exists() && child.isFile()); 76 } 77 78 85 public boolean hasDirectory(String path) { 86 87 File child = new File (file, path); 88 return (child.exists() && child.isDirectory()); 89 } 90 91 98 public List listContent(String path) { 99 100 File child = new File (file, path); 101 List <String > libs = new ArrayList <String >(); 102 if (child.isDirectory()) { 104 addContent(child, libs); 105 } 106 107 return libs; 108 } 109 110 117 private void addContent(File f, List <String > l) { 118 File [] childs = f.listFiles(); 119 if (childs != null) { 120 for (int i = 0; i < childs.length; i++) { 121 if (childs[i].isDirectory()) { 122 addContent(childs[i], l); 123 } else if (childs[i].isFile()) { 124 l.add(childs[i].getPath().substring(file.getPath().length())); 125 } 126 } 127 } 128 } 129 130 } 131 | Popular Tags |