Given a string:
String xml = "<test/>";
How do I convert it to an InputStream
in Groovy?
Currently I use:
IOUtils.toInputStream(xml, StandardCharsets.UTF_8)
It works, but I'm looking for some shorter and dependency-free way of doing that in Groovy.
Of course I know answer for Java, but it involves ugly creation of ByteArrayInputStream
. I'm looking for GDK way of solving that.
Has not much to do with Groovy, plain java:
InputStream stream = new ByteArrayInputStream( xml.getBytes( 'UTF-8' ) )
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