2

I have a stream (hooked to an azure blob) which contains strings and integers. The same stream is consumed by a .net process also.

In C# the writing and reading is done through the type specific methods of BinaryWriter and BinaryReader classes e,g., BinaryWriter.Write("path1;path2") and BinaryReader.ReadString().

In Java, I couldn't find the relevant libraries to achieve the same. Most of the InputStream methods are capable of reading the whole line of the string.

If there are such libraries in Java, please share with me.

2 Answers2

3

Most of the InputStream methods are capable of reading the whole line of the string.

None of the InputStream methods is capable of doing that.

What you're looking for is DataInputStreamand DataOutputStream.

user207421
  • 305,947
  • 44
  • 307
  • 483
1

If you are trying to read in data generated from BinaryWriter in C# you are going to have to mess with this on the bit level. The data you actually want is prefixed with an integer to show the length of the data. You can read about how the prefix is generated here:

C# BinaryWriter length prefix - UTF7 encoding

It's worth mentioning that from what I tested the length is written backwards. In my case the first two bytes of the file were 0xA0 0x54 convert this to binary to get 10100000 01010100. The first byte here starts with a 1 so it is not the last byte. The second byte starts with a 0 however so it is the last (or in this case first byte) for the length. So the resulting length prefix is 1010100 (taken from the last byte removing the indicator that it is the last byte) Then all previous bytes 0100000 which gives us the result of 10101000100000 or 10784 bytes. The file I was dealing with was 10786 bytes so with the two byte prefix indicating the length this is correct.

Renari
  • 822
  • 7
  • 16
  • 32