How can I transform a String
value into an InputStreamReader
?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I also found the apache commons
IOUtils
class , so :Does it have to be specifically an InputStreamReader? How about using StringReader?
Otherwise, you could use StringBufferInputStream, but it's deprecated because of character conversion issues (which is why you should prefer StringReader).
Are you trying to get a)
Reader
functionality out ofInputStreamReader
, or b)InputStream
functionality out ofInputStreamReader
? You won't get b).InputStreamReader
is not anInputStream
.The purpose of
InputStreamReader
is to take anInputStream
- a source of bytes - and decode the bytes to chars in the form of aReader
. You already have your data as chars (your original String). Encoding your String into bytes and decoding the bytes back to chars would be a redundant operation.If you are trying to get a
Reader
out of your source, useStringReader
.If you are trying to get an
InputStream
(which only gives you bytes), use apache commonsIOUtils.toInputStream(..)
as suggested by other answers here.Same question as @Dan - why not StringReader ?
If it has to be InputStreamReader, then:
ByteArrayInputStream also does the trick:
You can try Cactoos:
Then, if you need a
Reader
: