1*a5b190bfSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*a5b190bfSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*a5b190bfSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*a5b190bfSAndrew Rist  * distributed with this work for additional information
6*a5b190bfSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*a5b190bfSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*a5b190bfSAndrew Rist  * "License"); you may not use this file except in compliance
9*a5b190bfSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*a5b190bfSAndrew Rist  *
11*a5b190bfSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*a5b190bfSAndrew Rist  *
13*a5b190bfSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*a5b190bfSAndrew Rist  * software distributed under the License is distributed on an
15*a5b190bfSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a5b190bfSAndrew Rist  * KIND, either express or implied.  See the License for the
17*a5b190bfSAndrew Rist  * specific language governing permissions and limitations
18*a5b190bfSAndrew Rist  * under the License.
19*a5b190bfSAndrew Rist  *
20*a5b190bfSAndrew Rist  *************************************************************/
21*a5b190bfSAndrew Rist 
22*a5b190bfSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.lib.uno.adapter;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.io.IOException;
27cdf0e10cSrcweir import com.sun.star.io.XOutputStream;
28cdf0e10cSrcweir import java.io.OutputStream;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir /** The <code>OutputStreamToXOutputStreamAdapter</code> wraps
31cdf0e10cSrcweir    a a UNO <code>XOutputStream</code> into a Java <code>OutputStream</code>
32cdf0e10cSrcweir    object in a Java.  This allows users to access an <code>OutputStream</code>
33cdf0e10cSrcweir    as if it were an <code>XOutputStream</code>.
34cdf0e10cSrcweir  */
35cdf0e10cSrcweir public class OutputStreamToXOutputStreamAdapter implements XOutputStream {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir     /**
38cdf0e10cSrcweir      *  Internal handle to the OutputStream
39cdf0e10cSrcweir      */
40cdf0e10cSrcweir     OutputStream iOut;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir     /**
43cdf0e10cSrcweir      *  Constructor.
44cdf0e10cSrcweir      *
45cdf0e10cSrcweir      *  @param  out  The <code>XOutputStream</code> to be
46cdf0e10cSrcweir      *          accessed as an <code>OutputStream</code>.
47cdf0e10cSrcweir      */
OutputStreamToXOutputStreamAdapter(OutputStream out)48cdf0e10cSrcweir     public OutputStreamToXOutputStreamAdapter(OutputStream out) {
49cdf0e10cSrcweir         iOut = out;
50cdf0e10cSrcweir     }
51cdf0e10cSrcweir 
closeOutput()52cdf0e10cSrcweir     public void closeOutput() throws
53cdf0e10cSrcweir 			com.sun.star.io.IOException
54cdf0e10cSrcweir 	{
55cdf0e10cSrcweir         try {
56cdf0e10cSrcweir             iOut.close();
57cdf0e10cSrcweir         } catch (IOException e) {
58cdf0e10cSrcweir             throw new com.sun.star.io.IOException(e.toString());
59cdf0e10cSrcweir         }
60cdf0e10cSrcweir     }
61cdf0e10cSrcweir 
flush()62cdf0e10cSrcweir     public void flush() throws
63cdf0e10cSrcweir 			com.sun.star.io.IOException
64cdf0e10cSrcweir 	{
65cdf0e10cSrcweir         try {
66cdf0e10cSrcweir             iOut.flush();
67cdf0e10cSrcweir         } catch (IOException e) {
68cdf0e10cSrcweir             throw new com.sun.star.io.IOException(e.toString());
69cdf0e10cSrcweir         }
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir 
writeBytes(byte[] b)72cdf0e10cSrcweir     public void writeBytes(byte[] b) throws
73cdf0e10cSrcweir 			com.sun.star.io.IOException
74cdf0e10cSrcweir 	{
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 		try {
77cdf0e10cSrcweir 				iOut.write(b);
78cdf0e10cSrcweir 			} catch (IOException e) {
79cdf0e10cSrcweir 				throw new com.sun.star.io.IOException(e.toString());
80cdf0e10cSrcweir 			}
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir }
84