pyrrhic
pyrrhic

Reputation: 1897

DataOutputStream encoding and truncation

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)?

Upvotes: 4

Views: 5684

Answers (1)

Paul Wagland
Paul Wagland

Reputation: 29149

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.

Upvotes: 7

Related Questions