Convert akka ByteString to Java InputStream?

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

Answers (1)

LppEdd
LppEdd

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

Related Questions