1 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 19 20 21 class LocatorZip implements Locator 22 { 23 static Log log = LogFactory.getLog(LocatorZip.class) ; 24 String zipFileName = null ; 25 ZipFile zipFile = null ; 26 27 public LocatorZip(String 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 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 getName() { return "LocatorZip("+zipFileName+")" ; } 70 71 } 72 | Popular Tags |