KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > util > LocatorZip


1 /*
2  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  * [See end of file]
5  */

6
7 package com.hp.hpl.jena.util;
8
9 import com.hp.hpl.jena.shared.JenaException;
10 import java.io.* ;
11 import java.util.zip.* ;
12 import org.apache.commons.logging.*;
13
14 /** Location files in a zip file
15  *
16  * @author Andy Seaborne
17  * @version $Id: LocatorZip.java,v 1.3 2005/02/21 12:18:57 andy_seaborne Exp $
18  */

19  
20
21 class LocatorZip implements Locator
22 {
23     static Log log = LogFactory.getLog(LocatorZip.class) ;
24     String JavaDoc zipFileName = null ;
25     ZipFile zipFile = null ;
26     
27     public LocatorZip(String JavaDoc zfn)
28     {
29         try {
30             zipFileName = zfn ;
31             zipFile = new ZipFile(zipFileName) ;
32         } catch (IOException ex)
33         {
34             throw new JenaException("Problems accessing "+zipFileName, ex) ;
35         }
36     }
37     
38     public InputStream open(String JavaDoc filenameOrURI)
39     {
40         ZipEntry entry = zipFile.getEntry(filenameOrURI) ;
41         if ( entry == null )
42         {
43             if ( FileManager.logAllLookups && log.isDebugEnabled() )
44                 log.debug("Not found: "+zipFileName+" : "+filenameOrURI) ;
45             return null ;
46             
47         }
48         try
49         {
50             InputStream in = zipFile.getInputStream(entry) ;
51             
52             if ( in == null )
53             {
54                 if ( FileManager.logAllLookups && log.isTraceEnabled() )
55                     log.trace("Not found: "+filenameOrURI) ;
56                 return null ;
57             }
58             
59             if ( FileManager.logAllLookups && log.isTraceEnabled() )
60                 log.trace("Found: "+filenameOrURI) ;
61             return in;
62         }
63         catch (IOException ex)
64         {
65             log.warn("IO Exception opening zip entry: " + filenameOrURI);
66             return null;
67         }
68     }
69     public String JavaDoc getName() { return "LocatorZip("+zipFileName+")" ; }
70
71 }
72 /*
73  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
74  * All rights reserved.
75  *
76  * Redistribution and use in source and binary forms, with or without
77  * modification, are permitted provided that the following conditions
78  * are met:
79  * 1. Redistributions of source code must retain the above copyright
80  * notice, this list of conditions and the following disclaimer.
81  * 2. Redistributions in binary form must reproduce the above copyright
82  * notice, this list of conditions and the following disclaimer in the
83  * documentation and/or other materials provided with the distribution.
84  * 3. The name of the author may not be used to endorse or promote products
85  * derived from this software without specific prior written permission.
86  *
87  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
88  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
90  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
91  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
92  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
93  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
94  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
95  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
96  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97  */
Popular Tags