Reading file as binary

My service gets file over http request and i have to read this file with LibreOffice. I use XComponentLoader to read file. In order to read file i must save it to a folder first. Writing file to HD and reading it from HD has cost and make system more complicated than it should be.

Is there any way to send a file to libre Office as binary?

com.sun.star.io.SequenceInputStream?

Do u have any example about that?

Probably somewhere in the archives preserved - too lazy to look. Take from Andrew Pitonyak’s book, there are some examples of using streams.

@turhan Look at the MediaDecriptor service. The data that you pass to the loadComponentFromURL may include the InputStream PropertyValue. It might be possible to pass the stream without having a file; but in any case, I suppose that a valid URL (possibly pointing to a non-existing or empty file) will be required. You might look at LoadEnv::startLoading implementation, and my advise would be to use a debug build of LibreOffice, to be able to debug the code that you write, seeing the flow of the data, and at which points it breaks.

I forgot that i use java. :sweat_smile:
I am trying to to java equivalent of the code but sometimes i may be hard to convert-

The property of LibreOffice scripting model is that it really doesn’t matter. You use UNO; and it is uniform in any language (modulo the language syntax and type system - Java needs querying to get proper types, while Basic/Python are weakly-typed).

So nothing changes from your use of java.

I got error when i try this code
I get MultipartTamplateFile from http request.
XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop);

        PropertyValue[] props = new PropertyValue[2];
        props[0] = new PropertyValue();
        props[1] = new PropertyValue();
        props[0].Name = "InputStream";
        props[0].Value = multipartTemplate.getInputStream();
        props[1].Name = "Hidden";
        props[1].Value = true;
     XComponent xSpreadsheetComponent= xComponentLoader.loadComponentFromURL("private:stream", "_blank", 0, props);

Error is
com.sun.star.lang.DisposedException
at com.sun.star.lib.uno.environments.remote.JobQueue.removeJob(JobQueue.java:201)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:308)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:281)
at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:81)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:619)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:145)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:129)
at jdk.proxy2/jdk.proxy2.$Proxy77.loadComponentFromURL(Unknown Source)
at de.kybeidos.LibreOfficeExcelUpdater.util.StreamInserter.insert

I don’t know what is that, and what does it return in its getInputStream. Unfortunately, your code doesn’t allow us to repro.

You might want to create a sample, with a hard-coded minimal document binary data, as if you received it over the wire, and have the rest of the code. When such an example would succeed opening these bytes, you would win.