3

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(...){..}

`

8
  • Can we see a Minimal, Complete, and Verifiable example which demonstrates your problem? Commented Jul 30, 2016 at 9:29
  • This is what I have got. It seems stream.write changes to a byte array and its return type should be text. Don't know how to resolve it. Commented Jul 30, 2016 at 9:40
  • Try initialising stream. So StreamingOutput stream = new StreamingOutput(); Commented Jul 30, 2016 at 9:42
  • Thanks Dan. I forgot to put the method1(). stream gets the stream from method1(). Commented Jul 30, 2016 at 9:51
  • I am having trouble finding StreamingOutput. Would you mind linking me to the library you are using so that I can test the problem? Commented Jul 30, 2016 at 10:03

1 Answer 1

9

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(...){..}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks all. Solved.
The output was char array, not byte array, so it solved in that way. Thanks anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.