I'm working on a project these days, where I'm not responsible for the framework I have to work within. Now, ther are some problems with the encoding and special characters:
I've got to process text from an InputStream, and return an InputStream itself again. For this processing, I need the complete String from the given InputStream. Furthermore, I have to assume that the text in the InputStream contains every sort of characters, special characters and such. I assume, that the content of the InputStream is UTF-8 encoded.
Now, my first question is: Is this even possible? As far as I read, InputStreams work with bytes and byteArrays. byte can only take the values from -128 to 127, no? So, how can UTF-8 text be stored in an InputStream?
Now, assuming the answer to the question above is "yes" - I read the text from the Stream with an InputStreamReader, and I'm processing some form of output, as String.
How can I create an InputStream that contains the output, and ensure UTF-8 compatibility? Until now, I just found a possibility with ByteArrayInputStream, but they say it's deprecated, and I have to use a StringReader. But how can I convert/transform a StringReader into an InputStream?
-- PS: 1) Sorry for this post in the first place -- I had a total blackout and postet it in my mother language ^^
2) ByteArrayInputstream seems to work - but they say, that there is a more preferable way with StringReader. Mh.
Please translate your post to English. This is an international forum with a wide user base. I would say that most of us don't understand German. I myself can read it a bit but I would say I'm an exception. By using German for your post you are limiting the number of people who can help you out.
As for the answer, you can use String.getBytes(String encoding) in combination with a ByteArrayInputStream: