Reputation: 17953
In scala, how can an akka.util.ByteString
be converted to a java.io.InputStream
?
I tried the following:
val byteStringToInputStream : ByteString => InputStream =
byteStr => new ByteArrayInputStream(byteStr.asByteBuffer.array()))
But this results in an Exception being thrown
java.nio.ReadOnlyBufferException at java.nio.ByteBuffer.array(ByteBuffer.java:996)
Thank you in advance for your consideration and response.
Upvotes: 3
Views: 2654
Reputation: 21144
var byteArray = byteString.toArray()
var inputStream = new ByteArrayInputStream(byteArray)
P.S. not a Scala
developer (but a Java
one). Hope I got it right with syntax.
Upvotes: 10