update credits
[LibreOffice.git] / javaunohelper / com / sun / star / lib / uno / adapter / XOutputStreamToOutputStreamAdapter.java
blob8104cf42fa3c5deb0286f109973446de00c41e48
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.adapter;
21 import java.io.IOException;
23 import com.sun.star.io.XOutputStream;
25 import java.io.OutputStream;
27 /**
28 * The <code>XOutputStreamToOutputStreamAdapter</code> wraps
29 * the UNO <code>XOutputStream</code> object in a Java
30 * <code>OutputStream</code>. This allows users to access
31 * an <code>XOutputStream</code> as if it were an
32 * <code>OutputStream</code>.
34 public final class XOutputStreamToOutputStreamAdapter extends OutputStream {
36 /**
37 * Internal handle to the XInputStream
39 XOutputStream xout;
41 /**
42 * Constructor.
44 * @param out The <code>XOutputStream</code> to be
45 * accessed as an <code>OutputStream</code>.
47 public XOutputStreamToOutputStreamAdapter(XOutputStream out) {
48 xout = out;
51 @Override
52 public void close() throws IOException {
53 try {
54 xout.closeOutput();
55 } catch (Exception e) {
56 IOException newEx = new IOException(e.getMessage());
57 newEx.initCause(e);
58 throw newEx;
62 @Override
63 public void flush() throws IOException {
64 try {
65 xout.flush();
66 } catch (Exception e) {
67 IOException newEx = new IOException(e.getMessage());
68 newEx.initCause(e);
69 throw newEx;
73 @Override
74 public void write(byte[] b) throws IOException {
76 try {
77 xout.writeBytes(b);
78 } catch (Exception e) {
79 IOException newEx = new IOException(e.getMessage());
80 newEx.initCause(e);
81 throw newEx;
85 @Override
86 public void write(byte[] b, int off, int len) throws IOException {
88 byte[] tmp = new byte[len];
90 // Copy the input array into a temp array, and write it out.
92 System.arraycopy(b, off, tmp, 0, len);
94 try {
95 xout.writeBytes(tmp);
96 } catch (Exception e) {
97 IOException newEx = new IOException(e.getMessage());
98 newEx.initCause(e);
99 throw newEx;
103 @Override
104 public void write(int b) throws IOException {
106 byte [] oneByte = new byte [1];
107 oneByte[0] = (byte) b;
109 try {
110 xout.writeBytes(oneByte);
111 } catch (Exception e) {
112 IOException newEx = new IOException(e.getMessage());
113 newEx.initCause(e);
114 throw newEx;