Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataOutputStream encoding and truncation

Tags:

java

I am writing a socket programming application, and I'm wondering about DataOutputStream.

I have two questions:

  1. What is the default encoding for bytes sent from DataOutputStream?

  2. What is the max size of a String that OutputStream.writeBytes(String s) can send? Is it possible for the stream to truncate the String (and therefore be buggy)?

like image 230
pyrrhic Avatar asked Sep 15 '25 11:09

pyrrhic


1 Answers

Before talking about encoding in DataOutputStream, you need to say which method you are talking about:

  1. writeBytes
  2. writeChars
  3. writeUTF

In each case, the answer can be gleaned from looking at the javadoc:

  1. Random, it only writes the lower eight bits of the char out.
  2. Effectively UTF-16HE.
  3. Using a modified UTF-8 encoding.

To answer your second question, the only maximums on the string size that can be stored will be memory, otherwise you can't store the string, and free disk space.

like image 192
Paul Wagland Avatar answered Sep 18 '25 09:09

Paul Wagland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!