1 /* 2 * StorageNativeOutputStream.java 3 * 4 * Created on 1. September 2004, 10:20 5 */ 6 7 package com.sun.star.sdbcx.comp.hsqldb; 8 9 /** 10 * 11 * @author oj93728 12 */ 13 public class StorageNativeOutputStream { 14 static { NativeLibraries.load(); } 15 16 String name; 17 Object key; 18 19 /** Creates a new instance of StorageNativeOutputStream */ 20 public StorageNativeOutputStream(String _name,Object _key) { 21 name = _name; 22 key = _key; 23 openStream(name, (String)key, NativeStorageAccess.WRITE | NativeStorageAccess.TRUNCATE); 24 } 25 26 public native void openStream(String name,String key, int mode); 27 /** 28 * Writes <code>len</code> bytes from the specified byte array 29 * starting at offset <code>off</code> to this output stream. 30 * The general contract for <code>write(b, off, len)</code> is that 31 * some of the bytes in the array <code>b</code> are written to the 32 * output stream in order; element <code>b[off]</code> is the first 33 * byte written and <code>b[off+len-1]</code> is the last byte written 34 * by this operation. 35 * <p> 36 * The <code>write</code> method of <code>OutputStream</code> calls 37 * the write method of one argument on each of the bytes to be 38 * written out. Subclasses are encouraged to override this method and 39 * provide a more efficient implementation. 40 * <p> 41 * If <code>b</code> is <code>null</code>, a 42 * <code>NullPointerException</code> is thrown. 43 * <p> 44 * If <code>off</code> is negative, or <code>len</code> is negative, or 45 * <code>off+len</code> is greater than the length of the array 46 * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown. 47 * @param key The name of the data source. 48 * @param _file The name of the file to write to. 49 * @param b the data. 50 * @param off the start offset in the data. 51 * @param len the number of bytes to write. 52 * @exception IOException if an I/O error occurs. In particular, 53 * an <code>IOException</code> is thrown if the output 54 * stream is closed. 55 */ 56 public native void write(String key,String _file,byte[] b, int off, int len) throws java.io.IOException; 57 58 /** 59 * Writes <code>b.length</code> bytes from the specified byte array 60 * to this output stream. The general contract for <code>write(b)</code> 61 * is that it should have exactly the same effect as the call 62 * <code>write(b, 0, b.length)</code>. 63 * 64 * @param b the data. 65 * @exception IOException if an I/O error occurs. 66 * @see java.io.OutputStream#write(byte[], int, int) 67 */ 68 public native void write(String key,String _file,byte[] b) throws java.io.IOException; 69 70 /** 71 * Closes this output stream and releases any system resources 72 * associated with this stream. The general contract of <code>close</code> 73 * is that it closes the output stream. A closed stream cannot perform 74 * output operations and cannot be reopened. 75 * <p> 76 * The <code>close</code> method of <code>OutputStream</code> does nothing. 77 * @param key The name of the data source. 78 * @param _file The name of the file to write to. 79 * 80 * @exception IOException if an I/O error occurs. 81 */ 82 public native void close(String key,String _file) throws java.io.IOException; 83 84 /** 85 * Writes the specified byte to this output stream. The general 86 * contract for <code>write</code> is that one byte is written 87 * to the output stream. The byte to be written is the eight 88 * low-order bits of the argument <code>b</code>. The 24 89 * high-order bits of <code>b</code> are ignored. 90 * <p> 91 * Subclasses of <code>OutputStream</code> must provide an 92 * implementation for this method. 93 * 94 * @param key The name of the data source. 95 * @param _file The name of the file to write to. 96 * @param b the <code>byte</code>. 97 * @exception IOException if an I/O error occurs. In particular, 98 * an <code>IOException</code> may be thrown if the 99 * output stream has been closed. 100 */ 101 public native void write(String key,String _file,int b) throws java.io.IOException; 102 103 /** 104 * Flushes this output stream and forces any buffered output bytes 105 * to be written out. The general contract of <code>flush</code> is 106 * that calling it is an indication that, if any bytes previously 107 * written have been buffered by the implementation of the output 108 * stream, such bytes should immediately be written to their 109 * intended destination. 110 * <p> 111 * The <code>flush</code> method of <code>OutputStream</code> does nothing. 112 * @param key The name of the data source. 113 * @param _file The name of the file to write to. 114 * 115 * @exception IOException if an I/O error occurs. 116 */ 117 public native void flush(String key,String _file) throws java.io.IOException; 118 119 /** 120 * Force all system buffers to synchronize with the underlying 121 * device. This method returns after all modified data and 122 * attributes have been written to the relevant device(s). 123 * 124 * sync is meant to be used by code that requires physical 125 * storage (such as a file) to be in a known state For 126 * example, a class that provided a simple transaction facility 127 * might use sync to ensure that all changes to a file caused 128 * by a given transaction were recorded on a storage medium. 129 * 130 * sync only affects buffers downstream. If 131 * any in-memory buffering is being done by the application (for 132 * example, by a BufferedOutputStream object), those buffers must 133 * be flushed (for example, by invoking 134 * OutputStream.flush) before that data will be affected by sync. 135 * 136 * @exception IOException 137 * Thrown when the buffers cannot be flushed, 138 * or because the system cannot guarantee that all the 139 * buffers have been synchronized with physical media. 140 */ 141 public native void sync(String key,String _file) throws java.io.IOException; 142 143 } 144