2

I am trying to write a large String into my DataOutputStream however I am getting a UTFDataFormatException that says:

String more than 65535 UTF bytes long

This happens when I call:

byteOut.writeUTF(stringArray.get(i));

byteOut being my DataOutputStream and stringArray.get(i); being my string.

Is there anyway to get large string into this DataOutputStream or is there another solution.

Thanks!

StuStirling
  • 15,601
  • 23
  • 93
  • 150

2 Answers2

2

I found the solution to my problem and here it is.

ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream byteOut = new DataOutputStream(baos);
byte[] data = stringArray.get(i).getBytes("UTF-8");
byteOut.write(data);
byteOut.close();
byte[] input = baos.toByteArray();

May not be, and probably isn't perfect but it works.

Minas Mina
  • 2,058
  • 3
  • 21
  • 35
StuStirling
  • 15,601
  • 23
  • 93
  • 150
0

What are you using for creating the OutputStream? Take a look at this link: Here. Chances are the medium you're communicating over has constraints and you'll need to configure some parameters on the object.

Community
  • 1
  • 1
Grambot
  • 4,370
  • 5
  • 28
  • 43