bump product version to 5.0.4.1
[LibreOffice.git] / jurt / com / sun / star / lib / uno / bridges / java_remote / XConnectionInputStream_Adapter.java
blob7f65c3ba9c9582d6a6ea8e25828395ad8d60e749
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package com.sun.star.lib.uno.bridges.java_remote;
22 import java.io.IOException;
23 import java.io.InputStream;
25 import com.sun.star.connection.XConnection;
28 class XConnectionInputStream_Adapter extends InputStream {
29 static private final boolean DEBUG = false;
31 protected XConnection _xConnection;
32 protected byte _bytes[][] = new byte[1][];
34 XConnectionInputStream_Adapter(XConnection xConnection) {
35 if(xConnection == null) throw new NullPointerException("the XConnection must not be null");
37 if(DEBUG) System.err.println("#### " + getClass().getName() + " - instantiated ");
39 _xConnection = xConnection;
42 @Override
43 public int read() throws IOException {
44 int len;
46 try {
47 len = _xConnection.read(_bytes, 1);
48 } catch(com.sun.star.io.IOException ioException) {
49 IOException ex = new IOException(ioException.getMessage());
50 ex.initCause(ioException);
51 throw ex;
54 if(DEBUG) System.err.println("#### " + getClass().getName() + " - one byte read:" + _bytes[0][0]);
56 return len == 0 ? -1 : _bytes[0][0] & 0xff;
59 @Override
60 public int read(byte[] b, int off, int len) throws IOException {
61 try {
62 len = _xConnection.read(_bytes, len - off);
63 } catch(com.sun.star.io.IOException ioException) {
64 IOException ex = new IOException(ioException.getMessage());
65 ex.initCause(ioException);
66 throw ex;
69 System.arraycopy(_bytes[0], 0, b, off, len);
71 return len == 0 ? -1 : len;