01: /*
02:
03: Derby - Class org.apache.derby.impl.io.URLStorageFactory
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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.iapi.services.sanity.SanityManager;
25:
26: import org.apache.derby.io.StorageFactory;
27: import org.apache.derby.io.StorageFile;
28:
29: import java.io.FileNotFoundException;
30: import java.io.InputStream;
31: import java.io.OutputStream;
32: import java.io.IOException;
33:
34: /**
35: * This class provides a http based implementation of the StorageFactory interface. It is used by the
36: * database engine to access persistent data and transaction logs under the http and https subsubprotocols.
37: */
38:
39: public class URLStorageFactory extends BaseStorageFactory {
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: return new URLFile(this , path);
50: }
51:
52: /**
53: * Construct a StorageFile from a directory and file name.
54: *
55: * @param directoryName The directory part of the path name. Must not be null, nor may it be in the temp dir.
56: * @param fileName The name of the file within the directory.
57: *
58: * @return A corresponding StorageFile object
59: */
60: StorageFile newPersistentFile(String directoryName, String fileName) {
61: if (directoryName == null || directoryName.length() == 0)
62: return newPersistentFile(fileName);
63: return new URLFile(this , directoryName, fileName);
64: }
65:
66: /**
67: * Construct a StorageFile from a directory and file name.
68: *
69: * @param directoryName The directory part of the path name.
70: * @param fileName The name of the file within the directory.
71: *
72: * @return A corresponding StorageFile object
73: */
74: StorageFile newPersistentFile(StorageFile directoryName,
75: String fileName) {
76: if (directoryName == null)
77: return newPersistentFile(fileName);
78: return new URLFile((URLFile) directoryName, fileName);
79: }
80:
81: void doInit() throws IOException {
82: if (dataDirectory != null) {
83: if (dataDirectory.endsWith("/")) {
84: separatedDataDirectory = dataDirectory;
85: dataDirectory = dataDirectory.substring(0,
86: dataDirectory.length() - 1);
87: } else
88: separatedDataDirectory = dataDirectory + '/'; // URLs use '/' as a separator
89: canonicalName = dataDirectory;
90: createTempDir();
91: }
92: } // end of doInit
93: }
|