user2307087
user2307087

Reputation: 423

Converting StreamingOutput to a string

I am trying to convert StreamingOutput to string in Java to pass it to another method. It produces the string but it raises the following error later on.

JAXRSUtils logMessageHandlerProblem Severe: Problem with writing the data, ContentType: text/plain

What's happening?

StreamingOutput stream = method1();
ByteArrayOutputStream output = new ByteArrayOutputStream();
stream.write(output);
String string = new String(output.toString("UTF-8"));


...
public StreamingOutput method1(...){..}

`

Upvotes: 3

Views: 10132

Answers (1)

Carlos Galo Campos
Carlos Galo Campos

Reputation: 648

I believe you did not properly convert OutputStream to String properly. Please try the code below:

StreamingOutput stream = method1();
ByteArrayOutputStream output = new ByteArrayOutputStream();
stream.write(output);
String string = new String(output.toByteArray(), "UTF-8");


...
public StreamingOutput method1(...){..}

Upvotes: 9

Related Questions