1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 package com.sun.star.sdbcx.comp.hsqldb; 19 20 import org.hsqldb.lib.FileAccess; 21 import org.hsqldb.lib.FileSystemRuntimeException; 22 23 @SuppressWarnings("ucd") 24 public class StorageFileAccess implements org.hsqldb.lib.FileAccess{ NativeLibraries.load()25 static { NativeLibraries.load(); } 26 27 String ds_name; 28 String key; 29 /** Creates a new instance of StorageFileAccess */ StorageFileAccess(Object key)30 public StorageFileAccess(Object key) throws java.lang.Exception{ 31 this.key = (String)key; 32 } 33 createParentDirs(String filename)34 public void createParentDirs(String filename) { 35 } 36 isStreamElement(String elementName)37 public boolean isStreamElement(String elementName) { 38 return isStreamElement(key,elementName); 39 } 40 openInputStreamElement(String streamName)41 public java.io.InputStream openInputStreamElement(String streamName) throws java.io.IOException { 42 return new NativeInputStreamHelper(key,streamName); 43 } 44 openOutputStreamElement(String streamName)45 public java.io.OutputStream openOutputStreamElement(String streamName) throws java.io.IOException { 46 return new NativeOutputStreamHelper(key,streamName); 47 } 48 removeElement(String filename)49 public void removeElement(String filename) throws java.util.NoSuchElementException { 50 try { 51 if ( isStreamElement(key,filename) ) 52 removeElement(key,filename); 53 } catch (java.io.IOException e) { 54 throw new FileSystemRuntimeException( e ); 55 } 56 } 57 renameElement(String oldName, String newName)58 public void renameElement(String oldName, String newName) throws java.util.NoSuchElementException { 59 try { 60 if ( isStreamElement(key,oldName) ){ 61 removeElement(key,newName); 62 renameElement(key,oldName, newName); 63 } 64 } catch (java.io.IOException e) { 65 throw new FileSystemRuntimeException( e ); 66 } 67 } 68 69 private static class FileSync implements FileAccess.FileSync 70 { 71 private final NativeOutputStreamHelper os; FileSync(NativeOutputStreamHelper _os)72 private FileSync(NativeOutputStreamHelper _os) 73 { 74 os = _os; 75 } sync()76 public void sync() throws java.io.IOException 77 { 78 os.sync(); 79 } 80 } 81 getFileSync(java.io.OutputStream os)82 public FileAccess.FileSync getFileSync(java.io.OutputStream os) throws java.io.IOException 83 { 84 return new FileSync((NativeOutputStreamHelper)os); 85 } 86 isStreamElement(String key,String elementName)87 static native boolean isStreamElement(String key,String elementName); removeElement(String key,String filename)88 static native void removeElement(String key,String filename) throws java.util.NoSuchElementException, java.io.IOException; renameElement(String key,String oldName, String newName)89 static native void renameElement(String key,String oldName, String newName) throws java.util.NoSuchElementException, java.io.IOException; 90 } 91