1 /** 2 * 3 * Copyright 2005 The Apache Software Foundation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 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 /** 30 * @version $Rev: 410741 $ $Date: 2006-05-31 21:35:48 -0700 (Wed, 31 May 2006) $ 31 */ 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 /** 90 * Always return null. This could be implementd by verifing the signatures 91 * in the manifest file against the actual file, but we don't need this right now. 92 * @return null 93 */ 94 public Certificate[] getCertificates() { 95 return null; 96 } 97 }