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