C # equivalent for ByteArrayOutputStream in java

I have code javalike

ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(tokenBytes);
baos.write(signedData);
byte[] finalout = baos.toByteArray();

where tokenBytes and signedData are byte arrays. In c#I wrote how

 using (MemoryStream stream = new MemoryStream())
        {
            using (BinaryWriter writer = new BinaryWriter(stream))
            {
                writer.Write(tokenBytes);
                writer.Write(signature);
            }
            finalBytesToSend = stream.ToArray();

        }

where tokenBytes, signature and finaleBytesToSend are byte arrays.

Is it correct? OR is there any other way to do this?

+4
source share
1 answer

Presumably, I assume that you are writing a Java-C # serialization scheme. I think there are three things that you might want to be careful about:

  • This output of the Java byte array may contain a special delimiter at the end.
  • Java Big-Endian, ; # - Little Endian.
  • Java UTF-16 (Big Endian) # UTF-16 - Little Endian.

, Java #, ByteBuffer Java MemoryStream/BinaryReader/BinaryWrite #. UTF-16 Big Endian # - , int/long/double primitives. .

+1

Source: https://habr.com/ru/post/1529156/


All Articles