Java and .NET Streams compatibility through IKVM

In my current project, I use IKVM to cross-compile several Java libraries that deal with various aspects of XML. These libraries are then integrated with several .NET libraries and my main code. Everything is working fine, but I suspect there are several inefficiencies, especially in the area of ​​access to streaming data.

Many of the Java libraries can accept SAX stream classes or other stream objects, such as OutputStream, etc. In some cases, I can wrap the corresponding Java class in a coorisponding subclass of .NET to bridge the gap and provide seamless threading between the two languages. For example, we create a class that comes from both the .NET MemoryStream and the Java OutputStream. However, in most cases, the interface is complex and I have to pass entire lines - even if I have streams available on the .NET side, and the Java side accepts (different) stream classes (and vice versa).

In general, my question is: if someone encountered similar problems, transferring data to / from IKVM compiled libraries using streams and how were they solved or mitigated? Are there any third-party solutions to help bridge this gap? For example, the code that provides Java SAX wrappers for .NET XmlReader and / or XmlWriter will be very useful.

+4
source share
1 answer

I made some bridges for this kind of thing at Saxon . It is open source, so you can use whatever you find useful. Although I do not guarantee that they are complete and correct if you use them in ways different from how Saxon uses them.

DotNetInputStream maps a .NET stream to a Java InputStream.

DotNetOutputStream maps a .NET stream to a Java OutputStream.

DotNetReader maps .NET TextReader to Java Reader.

DotNetWriter maps .NET TextWriter to Java Writer.

For XML streams, Saxon has its own internal push / pull interfaces (Receiver and PullProvider, respectively), and there are classes that map both of them to the corresponding Java and .NET interfaces.

+4
source

All Articles