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