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 package com.sun.star.script.framework.io; 24 25 import java.io.InputStream; 26 import com.sun.star.io.XInputStream; 27 28 public class XInputStreamWrapper extends InputStream { 29 private XInputStream m_xInputStream; 30 XInputStreamWrapper(XInputStream xInputStream)31 public XInputStreamWrapper(XInputStream xInputStream) { 32 m_xInputStream = xInputStream; 33 } 34 read()35 public int read() throws java.io.IOException 36 { 37 byte[][] byteRet = new byte[1][0]; 38 long numRead; 39 40 try { 41 numRead = m_xInputStream.readBytes(byteRet, 1); 42 } 43 catch (com.sun.star.io.IOException ioe) { 44 throw new java.io.IOException(ioe.getMessage()); 45 } 46 47 if (numRead != 1) { 48 return -1; 49 } 50 return byteRet[0][0]; 51 } 52 read( byte[] b )53 public int read( byte[] b ) throws java.io.IOException 54 { 55 byte[][] byteRet = new byte[1][]; 56 byteRet[0] = b; 57 try 58 { 59 return m_xInputStream.readBytes( byteRet, b.length ); 60 } 61 catch ( com.sun.star.io.IOException ioe) 62 { 63 throw new java.io.IOException(ioe.getMessage()); 64 } 65 } 66 skip(long n)67 public long skip(long n) throws java.io.IOException 68 { 69 try { 70 m_xInputStream.skipBytes((int)n); 71 return n; 72 } 73 catch (com.sun.star.io.IOException ioe) { 74 throw new java.io.IOException(ioe.getMessage()); 75 } 76 } 77 available()78 public int available() throws java.io.IOException 79 { 80 try { 81 return m_xInputStream.available(); 82 } 83 catch (com.sun.star.io.IOException ioe) { 84 throw new java.io.IOException(ioe.getMessage()); 85 } 86 } 87 close()88 public void close() throws java.io.IOException 89 { 90 try { 91 m_xInputStream.closeInput(); 92 } 93 catch (com.sun.star.io.IOException ioe) { 94 throw new java.io.IOException(ioe.getMessage()); 95 } 96 } 97 98 } 99