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.
var byteArray = byteString.toArray()
var inputStream = new ByteArrayInputStream(byteArray)
PS not a Scala
developer (but a Java
one). Hope I got it right with syntax.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.