Closed
Description
It appears there are use cases where one wants to convert a java.io.Reader
to a java.io.InputStream
using a given charset, see this Stack Overflow question or this Baeldung article.
Guava already has this functionality implemented as ReaderInputStream
, but only exposes it for CharSource
(therefore not for Reader
), see also #642 (comment).
Would it make sense to expose it also for Reader
, e.g. as com.google.common.io.CharStreams.asInputStream(Reader, Charset)
?
Considerations:
- Users might want to specify buffer size?
- Users very likely want to specify behavior on unencodable chars, currently
ReaderInputStream
usesCodingErrorAction.REPLACE
for them