1 21 22 package org.apache.derby.impl.io; 23 24 import org.apache.derby.io.StorageFile; 25 import org.apache.derby.io.StorageRandomAccessFile; 26 27 import org.apache.derby.iapi.services.sanity.SanityManager; 28 29 import java.io.File ; 30 import java.io.InputStream ; 31 import java.io.OutputStream ; 32 import java.io.IOException ; 33 import java.io.FileNotFoundException ; 34 import java.net.MalformedURLException ; 35 import java.net.URL ; 36 import java.util.zip.ZipEntry ; 37 import java.util.zip.ZipFile ; 38 39 40 44 class JarDBFile extends InputStreamFile 45 { 46 47 private final JarStorageFactory storageFactory; 48 49 JarDBFile( JarStorageFactory storageFactory, String path) 50 { 51 super( storageFactory, path); 52 this.storageFactory = storageFactory; 53 } 54 55 JarDBFile( JarStorageFactory storageFactory, String parent, String name) 56 { 57 super( storageFactory, parent, name); 58 this.storageFactory = storageFactory; 59 } 60 61 JarDBFile( JarDBFile dir, String name) 62 { 63 super( dir,name); 64 this.storageFactory = dir.storageFactory; 65 } 66 67 private JarDBFile( JarStorageFactory storageFactory, String child, int pathLen) 68 { 69 super( storageFactory, child, pathLen); 70 this.storageFactory = storageFactory; 71 } 72 73 78 public boolean exists() 79 { 80 return getEntry() != null; 81 } 83 private ZipEntry getEntry() 84 { 85 return storageFactory.zipData.getEntry( path); 86 } 87 88 95 public long length() 96 { 97 ZipEntry entry = getEntry(); 98 if( entry == null) 99 return 0; 100 return entry.getSize(); 101 } 103 109 StorageFile getParentDir( int pathLen) 110 { 111 return new JarDBFile( storageFactory, path, pathLen); 112 } 113 114 121 public InputStream getInputStream( ) throws FileNotFoundException 122 { 123 ZipEntry zipEntry = getEntry( ); 124 if (zipEntry == null) 125 throw new java.io.FileNotFoundException (path); 126 127 try 128 { 129 return storageFactory.zipData.getInputStream(zipEntry); 130 } 131 catch( IOException ioe){ throw new java.io.FileNotFoundException (path);} 132 } 134 139 public String toString() 140 { 141 return path; 142 } 143 149 public URL getURL() throws MalformedURLException { 150 File pathFile = new File(storageFactory.zipData.getName()); 151 152 String pathFileURL = pathFile.toURL().toString(); 153 154 return new URL ("jar:" + pathFileURL + "!/" + path); 155 } 156 } 157 | Popular Tags |