KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > virtual > plugins > context > jar > NoCopyNestedJarHandler


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.virtual.plugins.context.jar;
23
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.jar.JarEntry JavaDoc;
29 import java.util.jar.JarFile JavaDoc;
30 import java.util.zip.ZipInputStream JavaDoc;
31
32 import org.jboss.virtual.spi.VFSContext;
33 import org.jboss.virtual.spi.VirtualFileHandler;
34
35 /**
36  * Nested Jar Handler.
37  *
38  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
39  * @version $Revision: 1.1 $
40  */

41 public class NoCopyNestedJarHandler extends AbstractJarHandler
42 {
43    /** serialVersionUID */
44    private static final long serialVersionUID = 1L;
45
46    /** The jar entry */
47    private transient JarEntry JavaDoc entry;
48    private NestedJarFromStream njar;
49
50    /**
51     * Create a new NestedJarHandler.
52     *
53     * @param context the context
54     * @param parent the parent
55     * @param parentJar the parent jar file
56     * @param entry the jar entry
57     * @param url the url
58     * @throws IOException for an error accessing the file system
59     * @throws IllegalArgumentException for a null context, url or vfsPath
60     */

61    public NoCopyNestedJarHandler(VFSContext context, VirtualFileHandler parent, JarFile JavaDoc parentJar, JarEntry JavaDoc entry, URL JavaDoc url) throws IOException JavaDoc
62    {
63       super(context, parent, url, getEntryName(entry));
64
65       
66       try
67       {
68          InputStream JavaDoc is = parentJar.getInputStream(entry);
69          ZipInputStream JavaDoc jis;
70          if( (is instanceof ZipInputStream JavaDoc) )
71          {
72             jis = (ZipInputStream JavaDoc) is;
73          }
74          else
75          {
76             jis = new ZipInputStream JavaDoc(is);
77          }
78          njar = new NestedJarFromStream(context, parent, jis, url, entry);
79       }
80       catch (IOException JavaDoc original)
81       {
82          // Fix the context of the error message
83
IOException JavaDoc e = new IOException JavaDoc("Error opening jar file: " + url + " reason=" + original.getMessage());
84          e.setStackTrace(original.getStackTrace());
85          throw e;
86       }
87       
88       this.entry = entry;
89    }
90    
91    /**
92     * Get the entry
93     *
94     * @return the file
95     */

96    protected JarEntry JavaDoc getEntry()
97    {
98       checkClosed();
99       return entry;
100    }
101
102    @Override JavaDoc
103    public long getLastModified() throws IOException JavaDoc
104    {
105       return getEntry().getTime();
106    }
107
108    @Override JavaDoc
109    public long getSize() throws IOException JavaDoc
110    {
111       return getEntry().getSize();
112    }
113
114    @Override JavaDoc
115    public InputStream JavaDoc openStream() throws IOException JavaDoc
116    {
117       return getJar().getInputStream(getEntry());
118    }
119
120    @Override JavaDoc
121    public VirtualFileHandler findChild(String JavaDoc path) throws IOException JavaDoc
122    {
123       return njar.findChild(path);
124    }
125
126    @Override JavaDoc
127    public List JavaDoc<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException JavaDoc
128    {
129       // TODO Auto-generated method stub
130
return super.getChildren(ignoreErrors);
131    }
132    
133 }
134
Popular Tags