开发者

Java and .NET Streams Interoperability Through IKVM

开发者 https://www.devze.com 2023-03-18 17:42 出处:网络
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 mainline code. Ev

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 mainline code. Everything works fine, but I suspect that there are several inefficiencies, 开发者_StackOverflowespecially in the area of stream-based data access.

Many of the Java libraries can accept streaming SAX classes or other streaming objects such as OutputStream, etc. In some cases I can wrap the appropriate Java class in a coorisponding .NET subclass to bridge the gap and provide seamless streaming between the two languages. For example, creating a class that derives from both the .NET MemoryStream and the Java OutputStream. In most cases however, the interface is challenging and I am left passing whole strings around - even though 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 anyone has encountered similar problems passing data to/from IKVM compiled libraries using streams and how were they solved or mitigated? Do any third-party solutions exist to help bridge this gap? For example, code that provides Java SAX wrappers for .NET XmlReader and/or XmlWriter would be very useful.


I've done some bridging classes for this kind of thing in Saxon. It's open source, so you can reuse anything you find useful. Though I don't guarantee that they're complete and correct if you use them in ways other than the way Saxon uses them.

DotNetInputStream maps a .NET stream to a Java InputStream.

DotNetOutputStream maps a .NET stream to a Java OutputStream.

DotNetReader maps a .NET TextReader to a Java Reader.

DotNetWriter maps a .NET TextWriter to a 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 these to/from the corresponding Java and .NET interfaces.

0

精彩评论

暂无评论...
验证码 换一张
取 消