1 17 package org.apache.geronimo.kernel.classloader; 18 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.io.File ; 22 import java.io.FileInputStream ; 23 import java.net.URL ; 24 import java.net.MalformedURLException ; 25 import java.security.cert.Certificate ; 26 import java.util.jar.Attributes ; 27 import java.util.jar.Manifest ; 28 29 32 public class DirectoryResourceHandle extends AbstractResourceHandle { 33 private final String name; 34 private final File file; 35 private final Manifest manifest; 36 private final URL url; 37 private final URL codeSource; 38 39 public DirectoryResourceHandle(String name, File file, File codeSource, Manifest manifest) throws MalformedURLException { 40 this.name = name; 41 this.file = file; 42 this.codeSource = codeSource.toURL(); 43 this.manifest = manifest; 44 url = file.toURL(); 45 } 46 47 public String getName() { 48 return name; 49 } 50 51 public URL getUrl() { 52 return url; 53 } 54 55 public URL getCodeSourceUrl() { 56 return codeSource; 57 } 58 59 public boolean isDirectory() { 60 return file.isDirectory(); 61 } 62 63 public InputStream getInputStream() throws IOException { 64 if (file.isDirectory()) { 65 return new IoUtil.EmptyInputStream(); 66 } 67 return new FileInputStream (file); 68 } 69 70 public int getContentLength() { 71 if (file.isDirectory() || file.length() > Integer.MAX_VALUE) { 72 return -1; 73 } else { 74 return (int) file.length(); 75 } 76 } 77 78 public Manifest getManifest() throws IOException { 79 return manifest; 80 } 81 82 public Attributes getAttributes() throws IOException { 83 if (manifest == null) { 84 return null; 85 } 86 return manifest.getAttributes(getName()); 87 } 88 89 94 public Certificate [] getCertificates() { 95 return null; 96 } 97 } 98 | Popular Tags |