--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.io.URLFile\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.io;\r
+\r
+import org.apache.derby.io.StorageFile;\r
+import org.apache.derby.io.StorageRandomAccessFile;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+import java.io.IOException;\r
+import java.io.FileNotFoundException;\r
+\r
+import java.net.URL;\r
+\r
+/**\r
+ * This class provides a class path based implementation of the StorageFile interface. It is used by the\r
+ * database engine to access persistent data and transaction logs under the classpath subsubprotocol.\r
+ */\r
+class URLFile extends InputStreamFile\r
+{\r
+\r
+ private final URLStorageFactory storageFactory;\r
+\r
+ URLFile( URLStorageFactory storageFactory, String path)\r
+ {\r
+ super( storageFactory, path);\r
+ this.storageFactory = storageFactory;\r
+ }\r
+\r
+ URLFile( URLStorageFactory storageFactory, String parent, String name)\r
+ {\r
+ super( storageFactory, parent, name);\r
+ this.storageFactory = storageFactory;\r
+ }\r
+\r
+ URLFile( URLFile dir, String name)\r
+ {\r
+ super( dir,name);\r
+ this.storageFactory = dir.storageFactory;\r
+ }\r
+\r
+ private URLFile( URLStorageFactory storageFactory, String child, int pathLen)\r
+ {\r
+ super( storageFactory, child, pathLen);\r
+ this.storageFactory = storageFactory;\r
+ }\r
+\r
+ /**\r
+ * Tests whether the named file exists.\r
+ *\r
+ * @return <b>true</b> if the named file exists, <b>false</b> if not.\r
+ */\r
+ public boolean exists()\r
+ {\r
+ try\r
+ {\r
+ InputStream is = getInputStream();\r
+ if( is == null)\r
+ return false;\r
+ is.close();\r
+ return true;\r
+ }\r
+ catch( IOException ioe){ return false;}\r
+ } // end of exists\r
+\r
+ /**\r
+ * Get the parent of this file.\r
+ *\r
+ * @param pathLen the length of the parent's path name.\r
+ */\r
+ StorageFile getParentDir( int pathLen)\r
+ {\r
+ return new URLFile( storageFactory, path, pathLen);\r
+ }\r
+ \r
+ /**\r
+ * Creates an input stream from a file name.\r
+ *\r
+ * @return an input stream suitable for reading from the file.\r
+ *\r
+ * @exception FileNotFoundException if the file is not found.\r
+ */\r
+ public InputStream getInputStream( ) throws FileNotFoundException\r
+ {\r
+ try\r
+ {\r
+ URL url = new URL( path);\r
+ return url.openStream();\r
+ }\r
+ catch( IOException ioe){ throw new java.io.FileNotFoundException(path);}\r
+ } // end of getInputStream\r
+}\r