Update ooo320-m1
[ooovba.git] / javaunohelper / com / sun / star / lib / uno / adapter / XOutputStreamToOutputStreamAdapter.java
blob0e5028762c01307acef4847c8fd495b648945baf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XOutputStreamToOutputStreamAdapter.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com.sun.star.lib.uno.adapter;
33 import java.io.IOException;
34 import com.sun.star.io.XOutputStream;
35 import java.io.OutputStream;
37 /**
38 * The <code>XOutputStreamToOutputStreamAdapter</code> wraps
39 * the UNO <code>XOutputStream</code> object in a Java
40 * <code>OutputStream</code>. This allows users to access
41 * an <code>XOutputStream</code> as if it were an
42 * <code>OutputStream</code>.
44 * @author Brian Cameron
46 public class XOutputStreamToOutputStreamAdapter extends OutputStream {
48 /**
49 * Internal handle to the XInputStream
51 XOutputStream xout;
53 /**
54 * Constructor.
56 * @param out The <code>XOutputStream</code> to be
57 * accessed as an <code>OutputStream</code>.
59 public XOutputStreamToOutputStreamAdapter(XOutputStream out) {
60 xout = out;
63 public void close() throws IOException {
64 try {
65 xout.closeOutput();
66 } catch (Exception e) {
67 throw new IOException(e.toString());
71 public void flush() throws IOException {
72 try {
73 xout.flush();
74 } catch (Exception e) {
75 throw new IOException(e.toString());
79 public void write(byte[] b) throws IOException {
81 try {
82 xout.writeBytes(b);
83 } catch (Exception e) {
84 throw new IOException(e.toString());
88 public void write(byte[] b, int off, int len) throws IOException {
90 byte[] tmp = new byte[len];
92 // Copy the input array into a temp array, and write it out.
94 System.arraycopy(b, off, tmp, 0, len);
96 try {
97 xout.writeBytes(tmp);
98 } catch (Exception e) {
99 throw new IOException(e.toString());
103 public void write(int b) throws IOException {
105 byte [] oneByte = new byte [1];
106 oneByte[0] = (byte) b;
108 try {
109 xout.writeBytes(oneByte);
110 } catch (Exception e) {
111 throw new IOException(e.toString());