summaryrefslogtreecommitdiff
path: root/javaunohelper/com/sun/star/lib/uno/adapter
diff options
context:
space:
mode:
Diffstat (limited to 'javaunohelper/com/sun/star/lib/uno/adapter')
-rwxr-xr-xjavaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java161
-rw-r--r--javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java166
-rw-r--r--javaunohelper/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java87
-rw-r--r--javaunohelper/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java207
-rwxr-xr-xjavaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java121
-rw-r--r--javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java111
-rw-r--r--javaunohelper/com/sun/star/lib/uno/adapter/makefile.mk54
7 files changed, 907 insertions, 0 deletions
diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java
new file mode 100755
index 000000000000..60b4fe009397
--- /dev/null
+++ b/javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java
@@ -0,0 +1,161 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+/*
+ * ByteArrayXInputStram.java
+ *
+ * Created on 10. April 2003, 15:45
+ */
+
+package com.sun.star.lib.uno.adapter;
+
+/**
+ *
+ * @author lo119109
+ */
+
+import com.sun.star.io.XInputStream;
+import com.sun.star.io.XSeekable;
+import com.sun.star.lib.uno.helper.ComponentBase;
+
+public 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) {
+ // System.err.println("ByteArrayXInputStream");
+ 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) {
+ // System.err.println("check failed no bytes!");
+ throw new com.sun.star.io.NotConnectedException("no bytes");
+ }
+ if(!m_open) {
+ // System.err.println("check failed: closed");
+ 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 {
+ // System.err.println("available() -> "+a);
+ return (int)a;
+ }
+ }
+
+ public void closeInput() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException {
+ // System.err.println("closeInput()");
+ _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 {
+ // System.err.println("readbytes(..., "+param+")");
+ _check();
+ try {
+ int remain = (int)(m_length - m_pos);
+ if (param > remain) param = remain;
+ /* ARGH!!! */
+ if (values[0] == null){
+ values[0] = new byte[param];
+ // System.err.println("allocated new buffer of "+param+" bytes");
+ }
+ System.arraycopy(m_bytes, m_pos, values[0], 0, param);
+ // System.err.println("readbytes() -> "+param);
+ m_pos += param;
+ return param;
+ } catch (ArrayIndexOutOfBoundsException ae) {
+ // System.err.println("readbytes() -> ArrayIndexOutOfBounds");
+ ae.printStackTrace();
+ throw new com.sun.star.io.BufferSizeExceededException("buffer overflow");
+ } catch (Exception e) {
+ // System.err.println("readbytes() -> Exception: "+e.getMessage());
+ e.printStackTrace();
+ throw new com.sun.star.io.IOException("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 {
+ // System.err.println("readSomebytes()");
+ 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 {
+ // System.err.println("skipBytes("+param+")");
+ _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 {
+ // System.err.println("getLength() -> "+m_length);
+ 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 {
+ // System.err.println("getPosition() -> "+m_pos);
+ 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 {
+ // System.err.println("seek("+param+")");
+ 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");
+ }
+
+ public void finalize() throws Throwable{
+ // System.err.println("finalizer called for ByteArrayXInputStream!");
+ super.finalize();
+ }
+
+}
diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
new file mode 100644
index 000000000000..f143bf82f12a
--- /dev/null
+++ b/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
@@ -0,0 +1,166 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+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 class InputStreamToXInputStreamAdapter implements XInputStream {
+
+ /**
+ * Internal store to the InputStream
+ */
+ private 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.toString());
+ }
+
+ 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.toString());
+ }
+ }
+
+ public int readBytes(byte[][] b, int len) throws
+ com.sun.star.io.IOException
+ {
+ int count = 0;
+ try {
+ long bytesRead=0;
+ 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.toString());
+ }
+ }
+
+ public int readSomeBytes(byte[][] b, int len) throws
+ com.sun.star.io.IOException
+ {
+ int count = 0;
+ try {
+ long bytesRead=0;
+ 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.toString());
+ }
+ }
+
+ public void skipBytes(int n) throws
+ com.sun.star.io.IOException
+ {
+ int avail;
+ int tmpLongVal = n;
+ int tmpIntVal;
+
+ try {
+ avail = iIn.available();
+ } catch (IOException e) {
+ throw new com.sun.star.io.IOException(e.toString());
+ }
+
+ do {
+ if (tmpLongVal >= Integer.MAX_VALUE) {
+ tmpIntVal = Integer.MAX_VALUE;
+ } else {
+ // Casting is safe here.
+ tmpIntVal = (int)tmpLongVal;
+ }
+ tmpLongVal -= tmpIntVal;
+
+ try {
+ iIn.skip(tmpIntVal);
+ } catch (IOException e) {
+ throw new com.sun.star.io.IOException(e.toString());
+ }
+ } while (tmpLongVal > 0);
+ }
+}
+
diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java
new file mode 100644
index 000000000000..0f69faffa4ae
--- /dev/null
+++ b/javaunohelper/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java
@@ -0,0 +1,87 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+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 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 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.toString());
+ }
+ }
+
+ public void flush() throws
+ com.sun.star.io.IOException
+ {
+ try {
+ iOut.flush();
+ } catch (IOException e) {
+ throw new com.sun.star.io.IOException(e.toString());
+ }
+ }
+
+ 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.toString());
+ }
+ }
+
+}
diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java
new file mode 100644
index 000000000000..696956964de7
--- /dev/null
+++ b/javaunohelper/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java
@@ -0,0 +1,207 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+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>.
+ *
+ * @author Brian Cameron
+ */
+public class XInputStreamToInputStreamAdapter extends InputStream {
+
+ /**
+ * Internal handle to the XInputStream
+ */
+ private XInputStream xin;
+
+ /**
+ * Constructor.
+ *
+ * @param in The <code>XInputStream</code> to be
+ * accessed as an <code>InputStream</code>.
+ */
+ public XInputStreamToInputStreamAdapter (XInputStream in) {
+ xin = in;
+ }
+
+ public int available() throws IOException {
+
+ int bytesAvail;
+
+ try {
+ bytesAvail = xin.available();
+ } catch (Exception e) {
+ throw new IOException(e.toString());
+ }
+
+ return(bytesAvail);
+ }
+
+ public void close() throws IOException {
+ try {
+ xin.closeInput();
+ } catch (Exception e) {
+ throw new IOException(e.toString());
+ }
+ }
+
+ 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) {
+ throw new IOException(e.toString());
+ }
+ }
+
+ 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) {
+ throw new IOException(e.toString());
+ }
+
+ return (bytesRead);
+ }
+
+ public int read(byte[] b, int off, int len) throws IOException {
+ int count = 0;
+ byte [][] tmp = new byte [1][b.length];
+ try {
+ long bytesRead=0;
+ 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) {
+ throw new IOException("reader error: "+e.toString());
+ }
+ }
+
+ public long skip(long n) throws IOException {
+
+ int avail;
+ long tmpLongVal = n;
+ int tmpIntVal;
+
+ try {
+ avail = xin.available();
+ } catch (Exception e) {
+ throw new IOException(e.toString());
+ }
+
+ 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) {
+ throw new IOException(e.toString());
+ }
+ } 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.
+ *
+ * @returns false
+ */
+ public boolean markSupported() {
+ return false;
+ }
+
+ public void mark(int readlimit) {
+ // Not supported.
+ }
+
+ public void reset() throws IOException {
+ // Not supported.
+ }
+}
+
diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java
new file mode 100755
index 000000000000..8812f02b0e35
--- /dev/null
+++ b/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java
@@ -0,0 +1,121 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+/*
+ * ByteArrayXOutputStream.java
+ *
+ * Created on 11. April 2003, 14:20
+ */
+
+package com.sun.star.lib.uno.adapter;
+
+/**
+ *
+ * @author lo119109
+ */
+
+import com.sun.star.io.*;
+import com.sun.star.lib.uno.helper.ComponentBase;
+
+public class XOutputStreamToByteArrayAdapter
+ extends ComponentBase
+ implements XOutputStream
+{
+ private int initialSize = 100240; // 10 kb
+ private int size = 0;
+ private int position = 0;
+ private boolean externalBuffer = false;
+ private boolean closed = 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;
+ // System.err.println("new outputbuffer with external storage");
+ } else {
+ size = initialSize;
+ buffer = new byte[size];
+ // System.err.println("new outputbuffer with internal storage");
+ }
+ }
+
+ 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;
+ }
+ closed = true;
+ }
+
+ 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
+ {
+ // System.err.println("writeBytes("+values.length+")");
+ if ( values.length > size-position )
+ {
+ if ( externalBuffer )
+ throw new BufferSizeExceededException("out of buffer space, cannot grow external buffer");
+ byte[] newBuffer = null;
+ while ( values.length > size-position )
+ size *= 2;
+ // System.err.println("new buffer size is "+size+" bytes.");
+ 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/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java
new file mode 100644
index 000000000000..e8f521b5e64e
--- /dev/null
+++ b/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java
@@ -0,0 +1,111 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+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>.
+ *
+ * @author Brian Cameron
+ */
+public 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;
+ }
+
+ public void close() throws IOException {
+ try {
+ xout.closeOutput();
+ } catch (Exception e) {
+ throw new IOException(e.toString());
+ }
+ }
+
+ public void flush() throws IOException {
+ try {
+ xout.flush();
+ } catch (Exception e) {
+ throw new IOException(e.toString());
+ }
+ }
+
+ public void write(byte[] b) throws IOException {
+
+ try {
+ xout.writeBytes(b);
+ } catch (Exception e) {
+ throw new IOException(e.toString());
+ }
+ }
+
+ 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) {
+ throw new IOException(e.toString());
+ }
+ }
+
+ public void write(int b) throws IOException {
+
+ byte [] oneByte = new byte [1];
+ oneByte[0] = (byte) b;
+
+ try {
+ xout.writeBytes(oneByte);
+ } catch (Exception e) {
+ throw new IOException(e.toString());
+ }
+ }
+}
diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/makefile.mk b/javaunohelper/com/sun/star/lib/uno/adapter/makefile.mk
new file mode 100644
index 000000000000..793f5fb1dc64
--- /dev/null
+++ b/javaunohelper/com/sun/star/lib/uno/adapter/makefile.mk
@@ -0,0 +1,54 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..$/..$/..$/..$/..
+
+PRJNAME = juhelper
+PACKAGE = com$/sun$/star$/lib$/uno$/adapter
+TARGET = com_sun_star_lib_uno_adapter
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+.INCLUDE: $(PRJ)$/util$/settings.pmk
+
+# --- Files --------------------------------------------------------
+
+JAVAFILES= \
+ XInputStreamToInputStreamAdapter.java \
+ XOutputStreamToOutputStreamAdapter.java \
+ InputStreamToXInputStreamAdapter.java \
+ OutputStreamToXOutputStreamAdapter.java \
+ ByteArrayToXInputStreamAdapter.java \
+ XOutputStreamToByteArrayAdapter.java
+
+
+JAVACLASSFILES= $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class)
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk