001 /** 002 * 003 * Copyright 2005 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.kernel.classloader; 018 019 import java.util.jar.JarFile; 020 import java.util.jar.JarEntry; 021 import java.util.jar.Manifest; 022 import java.util.jar.Attributes; 023 import java.net.URL; 024 import java.net.MalformedURLException; 025 import java.io.InputStream; 026 import java.io.IOException; 027 import java.security.cert.Certificate; 028 029 /** 030 * @version $Rev: 410741 $ $Date: 2006-05-31 21:35:48 -0700 (Wed, 31 May 2006) $ 031 */ 032 public class JarResourceHandle extends AbstractResourceHandle { 033 private final JarFile jarFile; 034 private final JarEntry jarEntry; 035 private final URL url; 036 private final URL codeSource; 037 038 public JarResourceHandle(JarFile jarFile, JarEntry jarEntry, URL codeSource) throws MalformedURLException { 039 this.jarFile = jarFile; 040 this.jarEntry = jarEntry; 041 this.url = JarFileUrlStreamHandler.createUrl(jarFile, jarEntry, codeSource); 042 this.codeSource = codeSource; 043 } 044 045 public String getName() { 046 return jarEntry.getName(); 047 } 048 049 public URL getUrl() { 050 return url; 051 } 052 053 public URL getCodeSourceUrl() { 054 return codeSource; 055 } 056 057 public boolean isDirectory() { 058 return jarEntry.isDirectory(); 059 } 060 061 public InputStream getInputStream() throws IOException { 062 return jarFile.getInputStream(jarEntry); 063 } 064 065 public int getContentLength() { 066 return (int) jarEntry.getSize(); 067 } 068 069 public Manifest getManifest() throws IOException { 070 return jarFile.getManifest(); 071 } 072 073 public Attributes getAttributes() throws IOException { 074 return jarEntry.getAttributes(); 075 } 076 077 public Certificate[] getCertificates() { 078 return jarEntry.getCertificates(); 079 } 080 }