I'm working with LogManager.readConfiguration()
which requires an InputStream whose contents I'd like to come from a string. Is there an equivalent of StringBufferInputStream
that's not deprecated, such as a ReaderToInputStreamAdaptor
?
Use the ByteArrayInputStream, and be careful to specify an appropriate character encoding. e.g.
ByteArrayInputStream(str.getBytes("UTF8"));
You need to worry about the character encoding to determine how each character is converted to a set of bytes. Note you can use the default getBytes()
method and specify the encoding the JVM runs with via -Dfile.encoding=...
See java.io.ByteArrayInputStream
String s = "test";
InputStream input = new ByteArrayInputStream(s.getBytes("UTF8"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With