KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > io > URLFile


1 /*
2
3    Derby - Class org.apache.derby.impl.io.URLFile
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

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.InputStream JavaDoc;
30 import java.io.OutputStream JavaDoc;
31 import java.io.IOException JavaDoc;
32 import java.io.FileNotFoundException JavaDoc;
33
34 import java.net.URL JavaDoc;
35
36 /**
37  * This class provides a class path based implementation of the StorageFile interface. It is used by the
38  * database engine to access persistent data and transaction logs under the classpath subsubprotocol.
39  */

40 class URLFile extends InputStreamFile
41 {
42
43     private final URLStorageFactory storageFactory;
44
45     URLFile( URLStorageFactory storageFactory, String JavaDoc path)
46     {
47         super( storageFactory, path);
48         this.storageFactory = storageFactory;
49     }
50
51     URLFile( URLStorageFactory storageFactory, String JavaDoc parent, String JavaDoc name)
52     {
53         super( storageFactory, parent, name);
54         this.storageFactory = storageFactory;
55     }
56
57     URLFile( URLFile dir, String JavaDoc name)
58     {
59         super( dir,name);
60         this.storageFactory = dir.storageFactory;
61     }
62
63     private URLFile( URLStorageFactory storageFactory, String JavaDoc child, int pathLen)
64     {
65         super( storageFactory, child, pathLen);
66         this.storageFactory = storageFactory;
67     }
68
69     /**
70      * Tests whether the named file exists.
71      *
72      * @return <b>true</b> if the named file exists, <b>false</b> if not.
73      */

74     public boolean exists()
75     {
76         try
77         {
78             InputStream JavaDoc is = getInputStream();
79             if( is == null)
80                 return false;
81             is.close();
82             return true;
83         }
84         catch( IOException JavaDoc ioe){ return false;}
85     } // end of exists
86

87     /**
88      * Get the parent of this file.
89      *
90      * @param pathLen the length of the parent's path name.
91      */

92     StorageFile getParentDir( int pathLen)
93     {
94         return new URLFile( storageFactory, path, pathLen);
95     }
96     
97     /**
98      * Creates an input stream from a file name.
99      *
100      * @return an input stream suitable for reading from the file.
101      *
102      * @exception FileNotFoundException if the file is not found.
103      */

104     public InputStream JavaDoc getInputStream( ) throws FileNotFoundException JavaDoc
105     {
106         try
107         {
108             URL JavaDoc url = new URL JavaDoc( path);
109             return url.openStream();
110         }
111         catch( IOException JavaDoc ioe){ throw new java.io.FileNotFoundException JavaDoc(path);}
112     } // end of getInputStream
113
}
114
Popular Tags