[Solved] Py implementation of Java ByteArrayXInputStream...

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

[Solved] Py implementation of Java ByteArrayXInputStream...

Post by _savage »

I'm trying to follow this example, but I haven't quite figured out how to use a byte[] as an input stream in Python. In Java there seems to exist an adapter called ByteArrayToXInputStreamAdapter. Does an equivalent exist for the Python implementation?
Last edited by _savage on Mon Oct 19, 2015 7:51 am, edited 1 time in total.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Python implementation of Java's ByteArrayXInputStreamAda

Post by Villeroy »

UNO module c.s.s.io provides XInputStream and XOutputStream
http://www.openoffice.org/api/docs/comm ... tream.html
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Python implementation of Java's ByteArrayXInputStreamAda

Post by _savage »

Villeroy wrote:UNO module c.s.s.io provides XInputStream and XOutputStream
Thanks, I saw those. But being interface declarations I still would have to come up with a class that implements these interfaces. What I was asking in my original question was if there is already a Python equivalent for this Java implementation ByteArrayXInputStreamAdapter. Might that even be part of the shipping UNO blob?
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Python implementation of Java's ByteArrayXInputStreamAda

Post by Villeroy »

This is beyond my knowledge.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Python implementation of Java's ByteArrayXInputStreamAda

Post by hanya »

Sometimes com.sun.star.io.SequenceInputStream service can be used to this task.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Python implementation of Java's ByteArrayXInputStreamAda

Post by _savage »

hanya: funny you say that! I just stumbled upon this code which uses the SequenceInputStream service :-) And based on that example, here's something that works for me:

Code: Select all

# Read the content of a file as byte[]
def _file2bytes(fname):                                                     
    with open(fname, "rb") as f:                                            
        return f.read()                                                     

# Create an XInputStream implementation from a byte[]
def _file2istream(fname):                                                   
    fbytes = _file2bytes(fname)                                             
    istream = context.ServiceManager.createInstanceWithContext("com.sun.star.io.SequenceInputStream", context)
    istream.initialize((uno.ByteSequence(fbytes),))                         
    return istream
Now I can just use that stream.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
Post Reply