0

I'm trying to send data from C# app, to Java using Named pipes. Data is in form of a custom object. C# writer initialization is below:

BinaryWriter writer = new BinaryWriter(new BufferedWriterStream(stream, (70 * 1024) + 512), defaultEncoding); 

defaultEncoding --> UTF-8

I'm able to write data to the pipe, but on Java side, having issues reading that custom object. What kind of stream would help in this case ?

I've tried DataInputStream, ByteArrayInputStream, ObjectInputStream, but nothing helps.

I need to get that data in Java, do some processing, and send it back to C#

  • You want to send a _custom object_ in binary form between C# and Java? I'd be curious to know how you represent that. Wouldn't it make more sense to serialize it to some common format (JSON, something else) and deserialize it on the other side.. What kind of _issues_ are you _having_. Have you tried this with something as simple as a simple array of bytes or a simple array of ints? – Flydog57 Dec 27 '18 at 19:49
  • I cannot modify the existing C# app. I've to write something in java which can handle that. C# is using BinaryWriter. The closest Java stream to that is DataInputStream. I get java.io.StreamCorruptedException: invalid stream header: With other streams, I tried reading into a byte[], but I can't interprete the data read, not sure if it's correct. –  Dec 27 '18 at 19:52
  • Possible duplicate of [How to open a Windows named pipe from Java?](https://stackoverflow.com/questions/634564/how-to-open-a-windows-named-pipe-from-java) – Duston Dec 27 '18 at 19:53
  • Nope. I already tried solutions from that post. Problem is reading the custom object in Java. –  Dec 27 '18 at 19:54
  • DataInputStream doesn't have a header so it doesn't do the check you suggest, but it does expect all data to be in big-endian format, I would assume your data in little endian format. You can use reverseBytes on all the types or use NIO and ByteBuffer to read all the data. – Peter Lawrey Dec 27 '18 at 20:22

0 Answers0