• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

InputStream, UTF-8/16 und Strings

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
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.

Thanks in Advance!
Simon
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic