1152cbc9dSAndrew Rist /************************************************************** 2152cbc9dSAndrew Rist * 3152cbc9dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4152cbc9dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5152cbc9dSAndrew Rist * distributed with this work for additional information 6152cbc9dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7152cbc9dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8152cbc9dSAndrew Rist * "License"); you may not use this file except in compliance 9152cbc9dSAndrew Rist * with the License. You may obtain a copy of the License at 10152cbc9dSAndrew Rist * 11152cbc9dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12152cbc9dSAndrew Rist * 13152cbc9dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14152cbc9dSAndrew Rist * software distributed under the License is distributed on an 15152cbc9dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16152cbc9dSAndrew Rist * KIND, either express or implied. See the License for the 17152cbc9dSAndrew Rist * specific language governing permissions and limitations 18152cbc9dSAndrew Rist * under the License. 19152cbc9dSAndrew Rist * 20152cbc9dSAndrew Rist *************************************************************/ 21152cbc9dSAndrew Rist 22cdf0e10cSrcweir /* 23cdf0e10cSrcweir * StorageNativeOutputStream.java 24cdf0e10cSrcweir * 25cdf0e10cSrcweir * Created on 1. September 2004, 10:20 26cdf0e10cSrcweir */ 27cdf0e10cSrcweir 28cdf0e10cSrcweir package com.sun.star.sdbcx.comp.hsqldb; 29cdf0e10cSrcweir 30cdf0e10cSrcweir /** 31cdf0e10cSrcweir * 32cdf0e10cSrcweir * @author oj93728 33cdf0e10cSrcweir */ 34cdf0e10cSrcweir public class StorageNativeOutputStream { NativeLibraries.load()35cdf0e10cSrcweir static { NativeLibraries.load(); } 36cdf0e10cSrcweir 37cdf0e10cSrcweir String name; 38cdf0e10cSrcweir Object key; 39cdf0e10cSrcweir 40cdf0e10cSrcweir /** Creates a new instance of StorageNativeOutputStream */ StorageNativeOutputStream(String _name,Object _key)41cdf0e10cSrcweir public StorageNativeOutputStream(String _name,Object _key) { 42cdf0e10cSrcweir name = _name; 43cdf0e10cSrcweir key = _key; 44cdf0e10cSrcweir openStream(name, (String)key, NativeStorageAccess.WRITE | NativeStorageAccess.TRUNCATE); 45cdf0e10cSrcweir } 46cdf0e10cSrcweir openStream(String name,String key, int mode)47cdf0e10cSrcweir public native void openStream(String name,String key, int mode); 48cdf0e10cSrcweir /** 49cdf0e10cSrcweir * Writes <code>len</code> bytes from the specified byte array 50cdf0e10cSrcweir * starting at offset <code>off</code> to this output stream. 51cdf0e10cSrcweir * The general contract for <code>write(b, off, len)</code> is that 52cdf0e10cSrcweir * some of the bytes in the array <code>b</code> are written to the 53cdf0e10cSrcweir * output stream in order; element <code>b[off]</code> is the first 54cdf0e10cSrcweir * byte written and <code>b[off+len-1]</code> is the last byte written 55cdf0e10cSrcweir * by this operation. 56cdf0e10cSrcweir * <p> 57cdf0e10cSrcweir * The <code>write</code> method of <code>OutputStream</code> calls 58cdf0e10cSrcweir * the write method of one argument on each of the bytes to be 59cdf0e10cSrcweir * written out. Subclasses are encouraged to override this method and 60cdf0e10cSrcweir * provide a more efficient implementation. 61cdf0e10cSrcweir * <p> 62cdf0e10cSrcweir * If <code>b</code> is <code>null</code>, a 63cdf0e10cSrcweir * <code>NullPointerException</code> is thrown. 64cdf0e10cSrcweir * <p> 65cdf0e10cSrcweir * If <code>off</code> is negative, or <code>len</code> is negative, or 66cdf0e10cSrcweir * <code>off+len</code> is greater than the length of the array 67cdf0e10cSrcweir * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown. 68cdf0e10cSrcweir * @param key The name of the data source. 69cdf0e10cSrcweir * @param _file The name of the file to write to. 70cdf0e10cSrcweir * @param b the data. 71cdf0e10cSrcweir * @param off the start offset in the data. 72cdf0e10cSrcweir * @param len the number of bytes to write. 73*e6b649b5SPedro Giffuni * @exception java.io.IOException if an I/O error occurs. In particular, 74cdf0e10cSrcweir * an <code>IOException</code> is thrown if the output 75cdf0e10cSrcweir * stream is closed. 76cdf0e10cSrcweir */ write(String key,String _file,byte[] b, int off, int len)77cdf0e10cSrcweir public native void write(String key,String _file,byte[] b, int off, int len) throws java.io.IOException; 78cdf0e10cSrcweir 79cdf0e10cSrcweir /** 80cdf0e10cSrcweir * Writes <code>b.length</code> bytes from the specified byte array 81cdf0e10cSrcweir * to this output stream. The general contract for <code>write(b)</code> 82cdf0e10cSrcweir * is that it should have exactly the same effect as the call 83cdf0e10cSrcweir * <code>write(b, 0, b.length)</code>. 84cdf0e10cSrcweir * 85cdf0e10cSrcweir * @param b the data. 86*e6b649b5SPedro Giffuni * @exception java.io.IOException if an I/O error occurs. 87cdf0e10cSrcweir * @see java.io.OutputStream#write(byte[], int, int) 88cdf0e10cSrcweir */ write(String key,String _file,byte[] b)89cdf0e10cSrcweir public native void write(String key,String _file,byte[] b) throws java.io.IOException; 90cdf0e10cSrcweir 91cdf0e10cSrcweir /** 92cdf0e10cSrcweir * Closes this output stream and releases any system resources 93cdf0e10cSrcweir * associated with this stream. The general contract of <code>close</code> 94cdf0e10cSrcweir * is that it closes the output stream. A closed stream cannot perform 95cdf0e10cSrcweir * output operations and cannot be reopened. 96cdf0e10cSrcweir * <p> 97cdf0e10cSrcweir * The <code>close</code> method of <code>OutputStream</code> does nothing. 98cdf0e10cSrcweir * @param key The name of the data source. 99cdf0e10cSrcweir * @param _file The name of the file to write to. 100cdf0e10cSrcweir * 101*e6b649b5SPedro Giffuni * @exception java.io.IOException if an I/O error occurs. 102cdf0e10cSrcweir */ close(String key,String _file)103cdf0e10cSrcweir public native void close(String key,String _file) throws java.io.IOException; 104cdf0e10cSrcweir 105cdf0e10cSrcweir /** 106cdf0e10cSrcweir * Writes the specified byte to this output stream. The general 107cdf0e10cSrcweir * contract for <code>write</code> is that one byte is written 108cdf0e10cSrcweir * to the output stream. The byte to be written is the eight 109cdf0e10cSrcweir * low-order bits of the argument <code>b</code>. The 24 110cdf0e10cSrcweir * high-order bits of <code>b</code> are ignored. 111cdf0e10cSrcweir * <p> 112cdf0e10cSrcweir * Subclasses of <code>OutputStream</code> must provide an 113cdf0e10cSrcweir * implementation for this method. 114cdf0e10cSrcweir * 115cdf0e10cSrcweir * @param key The name of the data source. 116cdf0e10cSrcweir * @param _file The name of the file to write to. 117cdf0e10cSrcweir * @param b the <code>byte</code>. 118*e6b649b5SPedro Giffuni * @exception java.io.IOException if an I/O error occurs. In particular, 119cdf0e10cSrcweir * an <code>IOException</code> may be thrown if the 120cdf0e10cSrcweir * output stream has been closed. 121cdf0e10cSrcweir */ write(String key,String _file,int b)122cdf0e10cSrcweir public native void write(String key,String _file,int b) throws java.io.IOException; 123cdf0e10cSrcweir 124cdf0e10cSrcweir /** 125cdf0e10cSrcweir * Flushes this output stream and forces any buffered output bytes 126cdf0e10cSrcweir * to be written out. The general contract of <code>flush</code> is 127cdf0e10cSrcweir * that calling it is an indication that, if any bytes previously 128cdf0e10cSrcweir * written have been buffered by the implementation of the output 129cdf0e10cSrcweir * stream, such bytes should immediately be written to their 130cdf0e10cSrcweir * intended destination. 131cdf0e10cSrcweir * <p> 132cdf0e10cSrcweir * The <code>flush</code> method of <code>OutputStream</code> does nothing. 133cdf0e10cSrcweir * @param key The name of the data source. 134cdf0e10cSrcweir * @param _file The name of the file to write to. 135cdf0e10cSrcweir * 136*e6b649b5SPedro Giffuni * @exception java.io.IOException if an I/O error occurs. 137cdf0e10cSrcweir */ flush(String key,String _file)138cdf0e10cSrcweir public native void flush(String key,String _file) throws java.io.IOException; 139cdf0e10cSrcweir 140cdf0e10cSrcweir /** 141cdf0e10cSrcweir * Force all system buffers to synchronize with the underlying 142cdf0e10cSrcweir * device. This method returns after all modified data and 143cdf0e10cSrcweir * attributes have been written to the relevant device(s). 144cdf0e10cSrcweir * 145cdf0e10cSrcweir * sync is meant to be used by code that requires physical 146cdf0e10cSrcweir * storage (such as a file) to be in a known state For 147cdf0e10cSrcweir * example, a class that provided a simple transaction facility 148cdf0e10cSrcweir * might use sync to ensure that all changes to a file caused 149cdf0e10cSrcweir * by a given transaction were recorded on a storage medium. 150cdf0e10cSrcweir * 151cdf0e10cSrcweir * sync only affects buffers downstream. If 152cdf0e10cSrcweir * any in-memory buffering is being done by the application (for 153cdf0e10cSrcweir * example, by a BufferedOutputStream object), those buffers must 154cdf0e10cSrcweir * be flushed (for example, by invoking 155cdf0e10cSrcweir * OutputStream.flush) before that data will be affected by sync. 156cdf0e10cSrcweir * 157cdf0e10cSrcweir * @exception IOException 158cdf0e10cSrcweir * Thrown when the buffers cannot be flushed, 159cdf0e10cSrcweir * or because the system cannot guarantee that all the 160cdf0e10cSrcweir * buffers have been synchronized with physical media. 161cdf0e10cSrcweir */ sync(String key,String _file)162cdf0e10cSrcweir public native void sync(String key,String _file) throws java.io.IOException; 163cdf0e10cSrcweir 164cdf0e10cSrcweir } 165