1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 /* 28 * StorageFileAccess.java 29 * 30 * Created on 31. August 2004, 11:56 31 */ 32 33 package com.sun.star.sdbcx.comp.hsqldb; 34 import org.hsqldb.lib.FileAccess; 35 import org.hsqldb.lib.FileSystemRuntimeException; 36 37 /** 38 * 39 * @author oj93728 40 */ 41 public class StorageFileAccess implements org.hsqldb.lib.FileAccess{ 42 static { NativeLibraries.load(); } 43 44 String ds_name; 45 String key; 46 /** Creates a new instance of StorageFileAccess */ 47 public StorageFileAccess(Object key) throws java.lang.Exception{ 48 this.key = (String)key; 49 } 50 51 public void createParentDirs(java.lang.String filename) { 52 } 53 54 public boolean isStreamElement(java.lang.String elementName) { 55 return isStreamElement(key,elementName); 56 } 57 58 public java.io.InputStream openInputStreamElement(java.lang.String streamName) throws java.io.IOException { 59 return new NativeInputStreamHelper(key,streamName); 60 } 61 62 public java.io.OutputStream openOutputStreamElement(java.lang.String streamName) throws java.io.IOException { 63 return new NativeOutputStreamHelper(key,streamName); 64 } 65 66 public void removeElement(java.lang.String filename) throws java.util.NoSuchElementException { 67 try { 68 if ( isStreamElement(key,filename) ) 69 removeElement(key,filename); 70 } catch (java.io.IOException e) { 71 throw new FileSystemRuntimeException( e, FileSystemRuntimeException.fileAccessRemoveElementFailed ); 72 } 73 } 74 75 public void renameElement(java.lang.String oldName, java.lang.String newName) throws java.util.NoSuchElementException { 76 try { 77 if ( isStreamElement(key,oldName) ){ 78 removeElement(key,newName); 79 renameElement(key,oldName, newName); 80 } 81 } catch (java.io.IOException e) { 82 throw new FileSystemRuntimeException( e, FileSystemRuntimeException.fileAccessRenameElementFailed ); 83 } 84 } 85 86 public class FileSync implements FileAccess.FileSync 87 { 88 NativeOutputStreamHelper os; 89 FileSync(NativeOutputStreamHelper _os) throws java.io.IOException 90 { 91 os = _os; 92 } 93 public void sync() throws java.io.IOException 94 { 95 os.sync(); 96 } 97 } 98 99 public FileAccess.FileSync getFileSync(java.io.OutputStream os) throws java.io.IOException 100 { 101 return new FileSync((NativeOutputStreamHelper)os); 102 } 103 104 static native boolean isStreamElement(java.lang.String key,java.lang.String elementName); 105 static native void removeElement(java.lang.String key,java.lang.String filename) throws java.util.NoSuchElementException, java.io.IOException; 106 static native void renameElement(java.lang.String key,java.lang.String oldName, java.lang.String newName) throws java.util.NoSuchElementException, java.io.IOException; 107 } 108