| 1 |
/* |
| 2 |
* This file is part of the LibreOffice project. |
| 3 |
* |
| 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/. |
| 7 |
* |
| 8 |
* This file incorporates work covered by the following license notice: |
| 9 |
* |
| 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 . |
| 17 |
*/ |
| 18 |
package com.sun.star.script.framework.io; |
| 19 |
|
| 20 |
import com.sun.star.io.XOutputStream; |
| 21 |
|
| 22 |
import java.io.IOException; |
| 23 |
import java.io.OutputStream; |
| 24 |
|
| 25 |
public class XOutputStreamWrapper extends OutputStream { |
| 26 |
|
| 27 |
private final XOutputStream m_xOutputStream; |
| 28 |
|
| 29 |
public XOutputStreamWrapper(XOutputStream xOs) { |
| 30 |
this.m_xOutputStream = xOs; |
| 31 |
} |
| 32 |
|
| 33 |
@Override |
| 34 |
public void write(int b) throws java.io.IOException { |
| 35 |
if (m_xOutputStream == null) { |
| 36 |
throw new java.io.IOException("Stream is null"); |
| 37 |
} |
| 38 |
|
| 39 |
byte[] bytes = new byte[1]; |
| 40 |
bytes[0] = (byte) b; |
| 41 |
|
| 42 |
try { |
| 43 |
m_xOutputStream.writeBytes(bytes); |
| 44 |
} catch (com.sun.star.io.IOException ex1) { |
| 45 |
IOException ex2 = new IOException(); |
| 46 |
ex2.initCause(ex1); |
| 47 |
throw ex2; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public void write(byte[] b) throws java.io.IOException { |
| 53 |
|
| 54 |
if (m_xOutputStream == null) { |
| 55 |
throw new java.io.IOException("Stream is null"); |
| 56 |
} |
| 57 |
|
| 58 |
try { |
| 59 |
m_xOutputStream.writeBytes(b); |
| 60 |
} catch (com.sun.star.io.IOException ex1) { |
| 61 |
IOException ex2 = new IOException(); |
| 62 |
ex2.initCause(ex1); |
| 63 |
throw ex2; |
| 64 |
} |
| 65 |
} |
| 66 |
@Override |
| 67 |
public void write(byte[] b, int off, int len) throws java.io.IOException { |
| 68 |
if (m_xOutputStream == null) { |
| 69 |
throw new java.io.IOException("Stream is null"); |
| 70 |
} |
| 71 |
|
| 72 |
byte[] bytes = new byte[len]; |
| 73 |
System.arraycopy(b, off, bytes, 0, len); |
| 74 |
|
| 75 |
try { |
| 76 |
m_xOutputStream.writeBytes(bytes); |
| 77 |
} catch (com.sun.star.io.IOException ex1) { |
| 78 |
IOException ex2 = new IOException(); |
| 79 |
ex2.initCause(ex1); |
| 80 |
throw ex2; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
@Override |
| 85 |
public void flush() throws java.io.IOException { |
| 86 |
if (m_xOutputStream == null) { |
| 87 |
throw new java.io.IOException("Stream is null"); |
| 88 |
} |
| 89 |
|
| 90 |
try { |
| 91 |
m_xOutputStream.flush(); |
| 92 |
} catch (com.sun.star.io.IOException ex1) { |
| 93 |
IOException ex2 = new IOException(); |
| 94 |
ex2.initCause(ex1); |
| 95 |
throw ex2; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
@Override |
| 100 |
public void close() throws java.io.IOException { |
| 101 |
if (m_xOutputStream == null) { |
| 102 |
throw new java.io.IOException("Stream is null"); |
| 103 |
} |
| 104 |
|
| 105 |
try { |
| 106 |
m_xOutputStream.closeOutput(); |
| 107 |
} catch (com.sun.star.io.IOException ex1) { |
| 108 |
IOException ex2 = new IOException(); |
| 109 |
ex2.initCause(ex1); |
| 110 |
throw ex2; |
| 111 |
} |
| 112 |
} |
| 113 |
} |