1 21 22 package org.apache.derby.impl.io; 23 24 import org.apache.derby.io.StorageFile; 25 26 import java.io.InputStream ; 27 28 import java.io.FileNotFoundException ; 29 import java.net.MalformedURLException ; 30 import java.net.URL ; 31 32 36 class CPFile extends InputStreamFile 37 { 38 39 private final CPStorageFactory storageFactory; 40 41 CPFile( CPStorageFactory storageFactory, String path) 42 { 43 super( storageFactory, path); 44 this.storageFactory = storageFactory; 45 } 46 47 CPFile( CPStorageFactory storageFactory, String parent, String name) 48 { 49 super( storageFactory, parent, name); 50 this.storageFactory = storageFactory; 51 } 52 53 CPFile( CPFile dir, String name) 54 { 55 super( dir,name); 56 this.storageFactory = dir.storageFactory; 57 } 58 59 private CPFile( CPStorageFactory storageFactory, String child, int pathLen) 60 { 61 super( storageFactory, child, pathLen); 62 this.storageFactory = storageFactory; 63 } 64 65 70 public boolean exists() 71 { 72 return getURL() != null; 73 } 75 80 StorageFile getParentDir( int pathLen) 81 { 82 return new CPFile( storageFactory, path, pathLen); 83 } 84 85 92 public InputStream getInputStream( ) throws FileNotFoundException 93 { 94 InputStream is = null; 96 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 97 if (cl != null) 98 is = cl.getResourceAsStream(path); 99 100 if (is == null) 103 { 104 cl = getClass().getClassLoader(); 105 if (cl != null) 109 is = cl.getResourceAsStream(path); 110 else 111 is = ClassLoader.getSystemResourceAsStream(path); 112 } 113 114 if (is == null) 115 throw new FileNotFoundException (toString()); 116 return is; 117 118 } 120 125 public URL getURL() { 126 127 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 128 URL myURL; 129 if (cl != null) { 130 myURL = cl.getResource(path); 131 if (myURL != null) 132 return myURL; 133 } 134 135 cl = getClass().getClassLoader(); 138 if (cl != null) { 142 return cl.getResource(path); 143 } else { 144 return ClassLoader.getSystemResource(path); 145 } 146 } 147 } 148 | Popular Tags |