1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.io.URLStorageFactory |
4 | |
5 | Copyright 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.io; |
22 | |
23 | import org.apache.derby.iapi.services.sanity.SanityManager; |
24 | |
25 | import org.apache.derby.io.StorageFactory; |
26 | import org.apache.derby.io.StorageFile; |
27 | |
28 | import java.io.FileNotFoundException; |
29 | import java.io.InputStream; |
30 | import java.io.OutputStream; |
31 | import java.io.IOException; |
32 | |
33 | /** |
34 | * This class provides a http based implementation of the StorageFactory interface. It is used by the |
35 | * database engine to access persistent data and transaction logs under the http and https subsubprotocols. |
36 | */ |
37 | |
38 | public class URLStorageFactory extends BaseStorageFactory |
39 | { |
40 | |
41 | /** |
42 | * Construct a persistent StorageFile from a path name. |
43 | * |
44 | * @param path The path name of the file |
45 | * |
46 | * @return A corresponding StorageFile object |
47 | */ |
48 | StorageFile newPersistentFile( String path) |
49 | { |
50 | return new URLFile( this, path); |
51 | } |
52 | |
53 | /** |
54 | * Construct a StorageFile from a directory and file name. |
55 | * |
56 | * @param directoryName The directory part of the path name. Must not be null, nor may it be in the temp dir. |
57 | * @param fileName The name of the file within the directory. |
58 | * |
59 | * @return A corresponding StorageFile object |
60 | */ |
61 | StorageFile newPersistentFile( String directoryName, String fileName) |
62 | { |
63 | if( directoryName == null || directoryName.length() == 0) |
64 | return newPersistentFile( fileName); |
65 | return new URLFile( this, directoryName, fileName); |
66 | } |
67 | |
68 | /** |
69 | * Construct a StorageFile from a directory and file name. |
70 | * |
71 | * @param directoryName The directory part of the path name. |
72 | * @param fileName The name of the file within the directory. |
73 | * |
74 | * @return A corresponding StorageFile object |
75 | */ |
76 | StorageFile newPersistentFile( StorageFile directoryName, String fileName) |
77 | { |
78 | if( directoryName == null) |
79 | return newPersistentFile( fileName); |
80 | return new URLFile( (URLFile) directoryName, fileName); |
81 | } |
82 | |
83 | void doInit() throws IOException |
84 | { |
85 | if( dataDirectory != null) |
86 | { |
87 | if( dataDirectory.endsWith( "/")) |
88 | { |
89 | separatedDataDirectory = dataDirectory; |
90 | dataDirectory = dataDirectory.substring( 0, dataDirectory.length() - 1); |
91 | } |
92 | else |
93 | separatedDataDirectory = dataDirectory + '/'; // URLs use '/' as a separator |
94 | canonicalName = dataDirectory; |
95 | createTempDir(); |
96 | } |
97 | } // end of doInit |
98 | } |