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.InputStream;
29 
30 import com.sun.star.connection.XConnection;
31 
32 
33 class XConnectionInputStream_Adapter extends InputStream {
34 	static private final boolean DEBUG = false;
35 
36 	protected XConnection _xConnection;
37 	protected byte        _bytes[][] = new byte[1][];
38 
XConnectionInputStream_Adapter(XConnection xConnection)39 	XConnectionInputStream_Adapter(XConnection xConnection) {
40 		if(xConnection == null)	throw new NullPointerException("the XConnection must not be null");
41 
42 		if(DEBUG) System.err.println("#### " + getClass().getName()  + " - instantiated ");
43 
44 		_xConnection = xConnection;
45 	}
46 
read()47 	public int read() throws IOException {
48 
49 		int len  ;
50 
51 		try {
52 			len = _xConnection.read(_bytes, 1);
53 		}
54 		catch(com.sun.star.io.IOException ioException) {
55 			throw new IOException(ioException.toString());
56 		}
57 
58 		if(DEBUG) System.err.println("#### " + getClass().getName()  + " - one byte read:" +  _bytes[0][0]);
59 
60 		return len == 0 ? -1 : _bytes[0][0] & 0xff;
61 	}
62 
read(byte[] b, int off, int len)63 	public int read(byte[] b, int off, int len) throws IOException {
64 // 		byte bytes[][] = new byte[1][];
65 
66 		try {
67 			len = _xConnection.read(_bytes, len - off);
68 		}
69 		catch(com.sun.star.io.IOException ioException) {
70 			throw new IOException(ioException.toString());
71 		}
72 
73 		System.arraycopy(_bytes[0], 0, b, off, len);
74 
75 		return len == 0 ? -1 : len;
76 	}
77 }
78 
79