1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  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,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 /*
24  * StorageFileAccess.java
25  *
26  * Created on 31. August 2004, 11:56
27  */
28 
29 package com.sun.star.sdbcx.comp.hsqldb;
30 import org.hsqldb.lib.FileAccess;
31 import org.hsqldb.lib.FileSystemRuntimeException;
32 
33 /**
34  *
35  * @author  oj93728
36  */
37 public class StorageFileAccess implements org.hsqldb.lib.FileAccess{
NativeLibraries.load()38     static { NativeLibraries.load(); }
39 
40     String ds_name;
41     String key;
42     /** Creates a new instance of StorageFileAccess */
StorageFileAccess(Object key)43     public StorageFileAccess(Object key) throws java.lang.Exception{
44         this.key = (String)key;
45     }
46 
createParentDirs(java.lang.String filename)47     public void createParentDirs(java.lang.String filename) {
48     }
49 
isStreamElement(java.lang.String elementName)50     public boolean isStreamElement(java.lang.String elementName)  {
51         return isStreamElement(key,elementName);
52     }
53 
openInputStreamElement(java.lang.String streamName)54     public java.io.InputStream openInputStreamElement(java.lang.String streamName) throws java.io.IOException {
55         return new NativeInputStreamHelper(key,streamName);
56     }
57 
openOutputStreamElement(java.lang.String streamName)58     public java.io.OutputStream openOutputStreamElement(java.lang.String streamName) throws java.io.IOException {
59         return new NativeOutputStreamHelper(key,streamName);
60     }
61 
removeElement(java.lang.String filename)62     public void removeElement(java.lang.String filename) throws java.util.NoSuchElementException {
63         try {
64             if ( isStreamElement(key,filename) )
65                 removeElement(key,filename);
66 	    } catch (java.io.IOException e) {
67            throw new FileSystemRuntimeException( e, FileSystemRuntimeException.fileAccessRemoveElementFailed );
68        }
69     }
70 
renameElement(java.lang.String oldName, java.lang.String newName)71     public void renameElement(java.lang.String oldName, java.lang.String newName) throws java.util.NoSuchElementException {
72         try {
73             if ( isStreamElement(key,oldName) ){
74                 removeElement(key,newName);
75                 renameElement(key,oldName, newName);
76             }
77        } catch (java.io.IOException e) {
78            throw new FileSystemRuntimeException( e, FileSystemRuntimeException.fileAccessRenameElementFailed );
79        }
80     }
81 
82     public class FileSync implements FileAccess.FileSync
83     {
84         NativeOutputStreamHelper os;
FileSync(NativeOutputStreamHelper _os)85         FileSync(NativeOutputStreamHelper _os) throws java.io.IOException
86         {
87             os = _os;
88         }
sync()89         public void sync() throws java.io.IOException
90         {
91             os.sync();
92         }
93     }
94 
getFileSync(java.io.OutputStream os)95     public FileAccess.FileSync getFileSync(java.io.OutputStream os) throws java.io.IOException
96     {
97         return new FileSync((NativeOutputStreamHelper)os);
98     }
99 
isStreamElement(java.lang.String key,java.lang.String elementName)100     static native boolean isStreamElement(java.lang.String key,java.lang.String elementName);
removeElement(java.lang.String key,java.lang.String filename)101     static native void removeElement(java.lang.String key,java.lang.String filename) throws java.util.NoSuchElementException, java.io.IOException;
renameElement(java.lang.String key,java.lang.String oldName, java.lang.String newName)102     static native void renameElement(java.lang.String key,java.lang.String oldName, java.lang.String newName) throws java.util.NoSuchElementException, java.io.IOException;
103 }
104