summaryrefslogtreecommitdiffstats
path: root/ridljar/com/sun/star/lib/uno/adapter
diff options
context:
space:
mode:
Diffstat (limited to 'ridljar/com/sun/star/lib/uno/adapter')
-rw-r--r--ridljar/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java117
-rw-r--r--ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java145
-rw-r--r--ridljar/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java80
-rw-r--r--ridljar/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java218
-rw-r--r--ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java94
-rw-r--r--ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java117
6 files changed, 771 insertions, 0 deletions
diff --git a/ridljar/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java
new file mode 100644
index 000000000..2d3e9a848
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java
@@ -0,0 +1,117 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+package com.sun.star.lib.uno.adapter;
+
+import com.sun.star.io.XInputStream;
+import com.sun.star.io.XSeekable;
+import com.sun.star.lib.uno.helper.ComponentBase;
+
+public final class ByteArrayToXInputStreamAdapter
+ extends ComponentBase
+ implements XInputStream, XSeekable
+{
+
+ byte[] m_bytes;
+ int m_length;
+ int m_pos;
+
+ boolean m_open;
+
+ /** Creates a new instance of ByteArrayXInputStram */
+ public ByteArrayToXInputStreamAdapter(byte[] bytes) {
+ init(bytes);
+ }
+
+ public void init(byte[] bytes) {
+ m_bytes = bytes;
+ m_length = bytes.length;
+ m_pos = 0;
+ m_open = true;
+ }
+
+ private void _check() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException {
+ if (m_bytes == null) {
+ throw new com.sun.star.io.NotConnectedException("no bytes");
+ }
+ if(!m_open) {
+ throw new com.sun.star.io.IOException("input closed");
+ }
+ }
+
+ public int available() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException {
+ _check();
+ long a = m_length - m_pos;
+ if (a != (int)a)
+ throw new com.sun.star.io.IOException("integer overflow");
+ else {
+ return (int)a;
+ }
+ }
+
+ public void closeInput() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException {
+ _check();
+ m_open = false;
+ }
+
+ public int readBytes(byte[][] values, int param) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException {
+ _check();
+ try {
+ int remain = (m_length - m_pos);
+ if (param > remain) param = remain;
+ /* ARGH!!! */
+ if (values[0] == null){
+ values[0] = new byte[param];
+ }
+ System.arraycopy(m_bytes, m_pos, values[0], 0, param);
+ m_pos += param;
+ return param;
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ throw new com.sun.star.io.BufferSizeExceededException(ex, "buffer overflow");
+ } catch (Exception ex) {
+ throw new com.sun.star.io.IOException(ex, "error accessing buffer");
+ }
+ }
+
+ public int readSomeBytes(byte[][] values, int param) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException {
+ return readBytes(values, param);
+ }
+
+ public void skipBytes(int param) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException {
+ _check();
+ if (param > (m_length - m_pos))
+ throw new com.sun.star.io.BufferSizeExceededException("buffer overflow");
+ m_pos += param;
+ }
+
+ public long getLength() throws com.sun.star.io.IOException {
+ if (m_bytes != null) return m_length;
+ else throw new com.sun.star.io.IOException("no bytes");
+ }
+
+ public long getPosition() throws com.sun.star.io.IOException {
+ if (m_bytes != null) return m_pos;
+ else throw new com.sun.star.io.IOException("no bytes");
+ }
+
+ public void seek(long param) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.io.IOException {
+ if (m_bytes != null){
+ if (param < 0 || param > m_length) throw new com.sun.star.lang.IllegalArgumentException("invalid seek position");
+ else m_pos = (int)param;
+ }else throw new com.sun.star.io.IOException("no bytes");
+ }
+}
diff --git a/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
new file mode 100644
index 000000000..3d60e5a11
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
@@ -0,0 +1,145 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+package com.sun.star.lib.uno.adapter;
+
+import java.io.IOException;
+
+import com.sun.star.io.XInputStream;
+
+import java.io.InputStream;
+
+/** The <code>InputStreamToInputXStreamAdapter</code> wraps the
+ Java <code>InputStream</code> object into a
+ UNO <code>XInputStream</code> object.
+ This allows users to access an <code>InputStream</code>
+ as if it were an <code>XInputStream</code>.
+ */
+public final class InputStreamToXInputStreamAdapter implements XInputStream {
+
+ /**
+ * Internal store to the InputStream
+ */
+ private final InputStream iIn;
+
+ /**
+ * Constructor.
+ *
+ * @param in The <code>XInputStream</code> to be
+ * accessed as an <code>InputStream</code>.
+ */
+ public InputStreamToXInputStreamAdapter (InputStream in)
+ {
+ iIn = in;
+ }
+
+ public int available() throws
+ com.sun.star.io.IOException
+ {
+
+ int bytesAvail;
+
+ try {
+ bytesAvail = iIn.available();
+ } catch (IOException e) {
+ throw new com.sun.star.io.IOException(e);
+ }
+
+ return bytesAvail;
+ }
+
+ public void closeInput() throws
+ com.sun.star.io.IOException
+ {
+ try {
+ iIn.close();
+ } catch (IOException e) {
+ throw new com.sun.star.io.IOException(e);
+ }
+ }
+
+ public int readBytes(byte[][] b, int len) throws
+ com.sun.star.io.IOException
+ {
+ try {
+ long bytesRead;
+ if (len >iIn.available()) {
+ bytesRead = iIn.read(b[0], 0, iIn.available());
+ }
+ else{
+ bytesRead = iIn.read(b[0], 0, len);
+ }
+ // Casting bytesRead to an int is okay, since the user can
+ // only pass in an integer length to read, so the bytesRead
+ // must <= len.
+
+ if (bytesRead <= 0) {
+ return 0;
+ }
+ return ((int)bytesRead);
+
+
+ } catch (IOException e) {
+ throw new com.sun.star.io.IOException("reader error", e);
+ }
+ }
+
+ public int readSomeBytes(byte[][] b, int len) throws
+ com.sun.star.io.IOException
+ {
+ try {
+ long bytesRead;
+ if (len >iIn.available()) {
+ bytesRead = iIn.read(b[0], 0, iIn.available());
+ }
+ else{
+ bytesRead = iIn.read(b[0], 0, len);
+ }
+ // Casting bytesRead to an int is okay, since the user can
+ // only pass in an integer length to read, so the bytesRead
+ // must <= len.
+
+ if (bytesRead <= 0) {
+ return 0;
+ }
+ return ((int)bytesRead);
+
+
+ } catch (IOException e) {
+ throw new com.sun.star.io.IOException("reader error", e);
+ }
+ }
+
+ public void skipBytes(int n) throws
+ com.sun.star.io.IOException
+ {
+ try {
+ iIn.available();
+ } catch (IOException e) {
+ throw new com.sun.star.io.IOException(e);
+ }
+
+ do {
+ try {
+ n -= iIn.skip(n);
+ } catch (IOException e) {
+ throw new com.sun.star.io.IOException(e);
+ }
+ } while (n > 0);
+ }
+}
+
diff --git a/ridljar/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java
new file mode 100644
index 000000000..2842e3df0
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java
@@ -0,0 +1,80 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.lib.uno.adapter;
+
+import java.io.IOException;
+
+import com.sun.star.io.XOutputStream;
+
+import java.io.OutputStream;
+
+/** The <code>OutputStreamToXOutputStreamAdapter</code> wraps
+ a UNO <code>XOutputStream</code> into a Java <code>OutputStream</code>
+ object in a Java. This allows users to access an <code>OutputStream</code>
+ as if it were an <code>XOutputStream</code>.
+ */
+public final class OutputStreamToXOutputStreamAdapter implements XOutputStream {
+
+ /**
+ * Internal handle to the OutputStream
+ */
+ OutputStream iOut;
+
+ /**
+ * Constructor.
+ *
+ * @param out The <code>XOutputStream</code> to be
+ * accessed as an <code>OutputStream</code>.
+ */
+ public OutputStreamToXOutputStreamAdapter(OutputStream out) {
+ iOut = out;
+ }
+
+ public void closeOutput() throws
+ com.sun.star.io.IOException
+ {
+ try {
+ iOut.close();
+ } catch (IOException e) {
+ throw new com.sun.star.io.IOException(e);
+ }
+ }
+
+ public void flush() throws
+ com.sun.star.io.IOException
+ {
+ try {
+ iOut.flush();
+ } catch (IOException e) {
+ throw new com.sun.star.io.IOException(e);
+ }
+ }
+
+ public void writeBytes(byte[] b) throws
+ com.sun.star.io.IOException
+ {
+
+ try {
+ iOut.write(b);
+ } catch (IOException e) {
+ throw new com.sun.star.io.IOException(e);
+ }
+ }
+
+}
diff --git a/ridljar/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java
new file mode 100644
index 000000000..25f1798fb
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java
@@ -0,0 +1,218 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+package com.sun.star.lib.uno.adapter;
+
+import java.io.IOException;
+
+import com.sun.star.io.XInputStream;
+
+import java.io.InputStream;
+
+/**
+ * The <code>XInputStreamToInputStreamAdapter</code> wraps
+ * the UNO <code>XInputStream</code> object in a Java
+ * <code>InputStream</code>. This allows users to access
+ * an <code>XInputStream</code> as if it were an
+ * <code>InputStream</code>.
+ */
+public final class XInputStreamToInputStreamAdapter extends InputStream {
+
+ /**
+ * Internal handle to the XInputStream
+ */
+ private final XInputStream xin;
+
+ /**
+ * Constructor.
+ *
+ * @param in The <code>XInputStream</code> to be
+ * accessed as an <code>InputStream</code>.
+ */
+ public XInputStreamToInputStreamAdapter (XInputStream in) {
+ xin = in;
+ }
+
+ @Override
+ public int available() throws IOException {
+
+ int bytesAvail;
+
+ try {
+ bytesAvail = xin.available();
+ } catch (Exception e) {
+ IOException newEx = new IOException(e.getMessage());
+ newEx.initCause(e);
+ throw newEx;
+ }
+
+ return bytesAvail;
+ }
+
+ @Override
+ public void close() throws IOException {
+ try {
+ xin.closeInput();
+ } catch (Exception e) {
+ IOException newEx = new IOException(e.getMessage());
+ newEx.initCause(e);
+ throw newEx;
+ }
+ }
+
+ @Override
+ public int read () throws IOException {
+ byte [][] tmp = new byte [1][1];
+ try {
+ long bytesRead = xin.readBytes(tmp, 1);
+
+ if (bytesRead <= 0) {
+ return (-1);
+ } else {
+ int tmpInt = tmp[0][0];
+ if (tmpInt< 0 ){
+ tmpInt = 256 +tmpInt;
+ }
+ return tmpInt;
+ }
+
+ } catch (Exception e) {
+ IOException newEx = new IOException(e.getMessage());
+ newEx.initCause(e);
+ throw newEx;
+ }
+ }
+
+ @Override
+ public int read (byte[] b) throws IOException {
+
+ byte [][] tmp = new byte [1][b.length];
+ int bytesRead;
+
+ try {
+ bytesRead = xin.readBytes(tmp, b.length);
+ if (bytesRead <= 0) {
+ return -1;
+ } else if (bytesRead < b.length) {
+ System.arraycopy(tmp[0], 0, b, 0, bytesRead);
+ } else {
+ System.arraycopy(tmp[0], 0, b, 0, b.length);
+ }
+ } catch (Exception e) {
+ IOException newEx = new IOException(e.getMessage());
+ newEx.initCause(e);
+ throw newEx;
+ }
+
+ return bytesRead;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ byte [][] tmp = new byte [1][b.length];
+ try {
+ long bytesRead;
+ int av = xin.available();
+ if ( av != 0 && len > av) {
+ bytesRead = xin.readBytes(tmp, av);
+ }
+ else{
+ bytesRead = xin.readBytes(tmp,len);
+ }
+ // Casting bytesRead to an int is okay, since the user can
+ // only pass in an integer length to read, so the bytesRead
+ // must <= len.
+
+ if (bytesRead <= 0) {
+ return -1;
+ } else if (bytesRead < len) {
+ System.arraycopy(tmp[0], 0, b, off, (int)bytesRead);
+ } else {
+ System.arraycopy(tmp[0], 0, b, off, len);
+ }
+
+ return ((int)bytesRead);
+ } catch (Exception e) {
+ IOException newEx = new IOException(e.getMessage());
+ newEx.initCause(e);
+ throw newEx;
+ }
+ }
+
+ @Override
+ public long skip(long n) throws IOException {
+
+ int avail;
+ long tmpLongVal = n;
+ int tmpIntVal;
+
+ try {
+ avail = xin.available();
+ } catch (Exception e) {
+ IOException newEx = new IOException(e.getMessage());
+ newEx.initCause(e);
+ throw newEx;
+ }
+
+ do {
+ if (tmpLongVal >= Integer.MAX_VALUE) {
+ tmpIntVal = Integer.MAX_VALUE;
+ } else {
+ // Casting is safe here.
+ tmpIntVal = (int)tmpLongVal;
+ }
+ tmpLongVal -= tmpIntVal;
+
+ try {
+ xin.skipBytes(tmpIntVal);
+ } catch (Exception e) {
+ IOException newEx = new IOException(e.getMessage());
+ newEx.initCause(e);
+ throw newEx;
+ }
+ } while (tmpLongVal > 0);
+
+ if ( avail != 0 && avail < n) {
+ return avail;
+ } else {
+ return n;
+ }
+ }
+
+ /**
+ * Tests if this input stream supports the mark and reset methods.
+ * The markSupported method of
+ * <code>XInputStreamToInputStreamAdapter</code> returns false.
+ *
+ * @return false
+ */
+ @Override
+ public boolean markSupported() {
+ return false;
+ }
+
+ @Override
+ public synchronized void mark(int readlimit) {
+ // Not supported.
+ }
+
+ @Override
+ public synchronized void reset() throws IOException {
+ // Not supported.
+ }
+}
+
diff --git a/ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java
new file mode 100644
index 000000000..48871277a
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java
@@ -0,0 +1,94 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+package com.sun.star.lib.uno.adapter;
+
+import com.sun.star.io.*;
+import com.sun.star.lib.uno.helper.ComponentBase;
+
+public final class XOutputStreamToByteArrayAdapter
+ extends ComponentBase
+ implements XOutputStream
+{
+ private static final int initialSize = 100240; // 10 kb
+ private int size = 0;
+ private int position = 0;
+ private boolean externalBuffer = false;
+ private byte[] buffer;
+
+ /** Creates a new instance of ByteArrayXOutputStream */
+ public XOutputStreamToByteArrayAdapter() {
+ this(null);
+ }
+
+ public XOutputStreamToByteArrayAdapter(byte[] aBuffer) {
+ if (aBuffer != null) {
+ externalBuffer = true;
+ buffer = aBuffer;
+ size = buffer.length;
+ } else {
+ size = initialSize;
+ buffer = new byte[size];
+ }
+ }
+
+ public byte[] getBuffer() {
+ return buffer;
+ }
+
+ public void closeOutput()
+ throws com.sun.star.io.NotConnectedException,
+ com.sun.star.io.BufferSizeExceededException,
+ com.sun.star.io.IOException
+ {
+ // trim buffer
+ if ( buffer.length > position && !externalBuffer )
+ {
+ byte[] newBuffer = new byte[position];
+ System.arraycopy(buffer, 0, newBuffer, 0, position);
+ buffer = newBuffer;
+ }
+ }
+
+ public void flush()
+ throws com.sun.star.io.NotConnectedException,
+ com.sun.star.io.BufferSizeExceededException,
+ com.sun.star.io.IOException
+ {
+ }
+
+ public void writeBytes(byte[] values)
+ throws com.sun.star.io.NotConnectedException,
+ com.sun.star.io.BufferSizeExceededException,
+ com.sun.star.io.IOException
+ {
+ if ( values.length > size-position )
+ {
+ if ( externalBuffer )
+ throw new BufferSizeExceededException("out of buffer space, cannot grow external buffer");
+ while ( values.length > size-position ) {
+ size *= 2;
+ }
+ byte[] newBuffer = new byte[size];
+ System.arraycopy(buffer, 0, newBuffer, 0, position);
+ buffer = newBuffer;
+ }
+ System.arraycopy(values, 0, buffer, position, values.length);
+ position += values.length;
+ }
+
+}
diff --git a/ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java
new file mode 100644
index 000000000..8104cf42f
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java
@@ -0,0 +1,117 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.lib.uno.adapter;
+
+import java.io.IOException;
+
+import com.sun.star.io.XOutputStream;
+
+import java.io.OutputStream;
+
+/**
+ * The <code>XOutputStreamToOutputStreamAdapter</code> wraps
+ * the UNO <code>XOutputStream</code> object in a Java
+ * <code>OutputStream</code>. This allows users to access
+ * an <code>XOutputStream</code> as if it were an
+ * <code>OutputStream</code>.
+ */
+public final class XOutputStreamToOutputStreamAdapter extends OutputStream {
+
+ /**
+ * Internal handle to the XInputStream
+ */
+ XOutputStream xout;
+
+ /**
+ * Constructor.
+ *
+ * @param out The <code>XOutputStream</code> to be
+ * accessed as an <code>OutputStream</code>.
+ */
+ public XOutputStreamToOutputStreamAdapter(XOutputStream out) {
+ xout = out;
+ }
+
+ @Override
+ public void close() throws IOException {
+ try {
+ xout.closeOutput();
+ } catch (Exception e) {
+ IOException newEx = new IOException(e.getMessage());
+ newEx.initCause(e);
+ throw newEx;
+ }
+ }
+
+ @Override
+ public void flush() throws IOException {
+ try {
+ xout.flush();
+ } catch (Exception e) {
+ IOException newEx = new IOException(e.getMessage());
+ newEx.initCause(e);
+ throw newEx;
+ }
+ }
+
+ @Override
+ public void write(byte[] b) throws IOException {
+
+ try {
+ xout.writeBytes(b);
+ } catch (Exception e) {
+ IOException newEx = new IOException(e.getMessage());
+ newEx.initCause(e);
+ throw newEx;
+ }
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+
+ byte[] tmp = new byte[len];
+
+ // Copy the input array into a temp array, and write it out.
+
+ System.arraycopy(b, off, tmp, 0, len);
+
+ try {
+ xout.writeBytes(tmp);
+ } catch (Exception e) {
+ IOException newEx = new IOException(e.getMessage());
+ newEx.initCause(e);
+ throw newEx;
+ }
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+
+ byte [] oneByte = new byte [1];
+ oneByte[0] = (byte) b;
+
+ try {
+ xout.writeBytes(oneByte);
+ } catch (Exception e) {
+ IOException newEx = new IOException(e.getMessage());
+ newEx.initCause(e);
+ throw newEx;
+ }
+ }
+}