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 import java.io.*; 25 import com.sun.star.io.XOutputStream; 26 27 28 public class XOutputStreamWrapper extends OutputStream { 29 XOutputStream m_xOutputStream; XOutputStreamWrapper(XOutputStream xOs )30 public XOutputStreamWrapper(XOutputStream xOs ) { 31 this.m_xOutputStream = xOs; 32 } write(int b)33 public void write(int b) 34 throws java.io.IOException 35 { 36 if ( m_xOutputStream == null ) 37 { 38 throw new java.io.IOException("Stream is null"); 39 } 40 byte[] bytes = new byte[1]; 41 bytes[0] = (byte) b; 42 try 43 { 44 m_xOutputStream.writeBytes( bytes ); 45 } 46 catch ( com.sun.star.io.IOException ioe ) 47 { 48 throw new java.io.IOException(ioe.getMessage()); 49 } 50 } write(byte[] b)51 public void write(byte[] b) 52 throws java.io.IOException 53 { 54 55 if ( m_xOutputStream == null ) 56 { 57 throw new java.io.IOException( "Stream is null" ); 58 } 59 try 60 { 61 m_xOutputStream.writeBytes( b ); 62 } 63 catch ( com.sun.star.io.IOException ioe ) 64 { 65 throw new java.io.IOException(ioe.getMessage()); 66 } 67 } write( byte[] b, int off, int len )68 public void write( byte[] b, int off, int len ) 69 throws java.io.IOException 70 { 71 if ( m_xOutputStream == null ) 72 { 73 throw new java.io.IOException( "Stream is null" ); 74 } 75 byte[] bytes = new byte[len]; 76 for ( int i=off; i< off+len; i++ ) 77 { 78 bytes[i] = b[i]; 79 } 80 try 81 { 82 m_xOutputStream.writeBytes(bytes); 83 } 84 catch ( com.sun.star.io.IOException ioe ) 85 { 86 throw new java.io.IOException(ioe.getMessage()); 87 } 88 } 89 flush()90 public void flush() 91 throws java.io.IOException 92 { 93 if ( m_xOutputStream == null ) 94 { 95 throw new java.io.IOException( "Stream is null" ); 96 } 97 try 98 { 99 m_xOutputStream.flush(); 100 } 101 catch ( com.sun.star.io.IOException ioe ) 102 { 103 throw new java.io.IOException(ioe.getMessage()); 104 } 105 } close()106 public void close() 107 throws java.io.IOException 108 { 109 if ( m_xOutputStream == null ) 110 { 111 throw new java.io.IOException( "Stream is null" ); 112 } 113 try 114 { 115 m_xOutputStream.closeOutput(); 116 } 117 catch ( com.sun.star.io.IOException ioe ) 118 { 119 throw new java.io.IOException(ioe.getMessage()); 120 } 121 } 122 123 } 124 125