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 
24 package com.sun.star.lib.uno.bridges.java_remote;
25 
26 
27 import java.io.IOException;
28 import java.io.OutputStream;
29 
30 import com.sun.star.connection.XConnection;
31 
32 
33 class XConnectionOutputStream_Adapter extends OutputStream {
34 	static private final boolean DEBUG = false;
35 
36 	protected XConnection _xConnection;
37 	protected byte _bytes[] = new byte[1];
38 
XConnectionOutputStream_Adapter(XConnection xConnection)39 	XConnectionOutputStream_Adapter(XConnection xConnection) {
40 		if(DEBUG) System.err.println("#### " + this.getClass()  + " - instantiated ");
41 
42 		_xConnection = xConnection;
43 	}
44 
write(int b)45 	public void write(int b) throws IOException {
46 		_bytes[0] = (byte)b;
47 
48 		try {
49 			_xConnection.write(_bytes);
50 		}
51 		catch(com.sun.star.io.IOException ioException) {
52 			throw new IOException(ioException.toString());
53 		}
54 
55 		if(DEBUG) System.err.println("#### " + this.getClass()  + " - one byte written:" +  _bytes[0]);
56 	}
57 
write(byte[] b, int off, int len)58 	public void write(byte[] b, int off, int len) throws IOException {
59 		byte bytes[]  ;
60 
61         if(off == 0 && len == b.length)
62             bytes = b;
63 
64         else {
65             bytes = new byte[len];
66 
67             System.arraycopy(b, off, bytes, 0, len);
68         }
69 
70 		try {
71 			_xConnection.write(bytes);
72 		}
73 		catch(com.sun.star.io.IOException ioException) {
74 			throw new IOException(ioException.toString());
75 		}
76 	}
77 
flush()78 	public void flush() throws IOException {
79 		try {
80 			_xConnection.flush();
81 		}
82 		catch(com.sun.star.io.IOException ioException) {
83 			throw new IOException(ioException.toString());
84 		}
85 	}
86 }
87 
88