-2

This is a continuation of HTML tags are getting converted

When I try to the following

 ByteArrayOutputStream stream= new ByteArrayOutputStream();
 stream= stream.toString().replaceAll("&lt;","<");

I am getting

incompatible types; found: class java.lang.String, required: class java.io.ByteArrayOutputStream

How can I replace &lt; with <

As mentioned in the other question, my HTML tags are getting converted and due to this reason before I print to open the HTML page, I would like to convert < to < if it exist in the stream.

Kindly suggest the reason for down voting as it makes sense rather than down voting for the sake of it.

Community
  • 1
  • 1
Jacob
  • 14,463
  • 65
  • 207
  • 320
  • 1
    I think the downvoter's reason is that you haven't given enough context of what you're planning on doing with this string. `replaceAll("<","<")` will indeed do the replacement you want... – qxz Nov 26 '16 at 07:48
  • @qxz Yes, point noted and accepted. Thanks – Jacob Nov 26 '16 at 07:49

1 Answers1

1

You're trying to assign the result of replaceAll (a String) to stream, a ByteArrayOutputStream. I think you mean to just create a new variable of type String:

ByteArrayOutputStream stream= new ByteArrayOutputStream();
String str = stream.toString().replaceAll("&lt;","<");

You can then convert the String to a byte array, using getBytes:

byte[] bytes = str.getBytes();
qxz
  • 3,814
  • 1
  • 14
  • 29
  • With this how I can I change the values in the stream instance of ByteArrayOutputStream? Idea is to replace values in stream instance. – Jacob Nov 26 '16 at 07:29
  • Sorry for being ignorant, how do I assign bytes to stream because what I intend to convert is a small part of the value or data exists in stream instance as it contains a lot of XML code. Please see [this](http://stackoverflow.com/questions/40815286/html-tags-are-getting-converted) as this is a continuation. – Jacob Nov 26 '16 at 07:35
  • 1
    You can't change the contents of the stream (except for writing to the end, of course). At what point do you want the HTML converted? How are you intending on eventually using this stream/byte array? – qxz Nov 26 '16 at 07:39
  • As mentioned in the other question, my HTML tags are getting converted and due to this reason before I print to open the HTML page, I would like to convert `<` to `<` if it exist in the stream. Thanks – Jacob Nov 26 '16 at 07:42
  • You should add the surrounding code in your question, including how/when you send the HTML. Then I'll be able to help you better. – qxz Nov 26 '16 at 07:50
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/129098/discussion-between-user75ponic-and-qxz). – Jacob Nov 26 '16 at 07:52
  • I am using string replaceAll method and using StringWriter to write all the converted string to have output in HTML format. Thanks – Jacob Nov 27 '16 at 16:16