Convert Source[ByteStream] to Java InputStream

790 views
Skip to first unread message

Michael Hamrah

unread,
May 27, 2015, 3:20:11 PM5/27/15
to akka...@googlegroups.com
I'm working with an akka-http application that takes in a POST request and needs to convert the body to a java.io.InputStream. Specifically, I need to go from a Source[akka.util.ByteString, Any] (which is what request.entity.dataBytes returns) to a java.io.InputStream. I can't seem to find the magic to make the conversion work. Can someone point me in the right direction? Seems like I'm missing an implicit conversion or a wrapping class.

Thanks,

Mike

Roland Kuhn

unread,
May 27, 2015, 3:32:46 PM5/27/15
to akka-user
Yes, you’re missing InputStreamSink. It is not terribly complicated to write, I think, but we have not yet gotten around to it.

Regards,

Roland

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Reactive apps on the JVM.
twitter: @rolandkuhn


Viktor Klang

unread,
May 27, 2015, 3:43:54 PM5/27/15
to Akka User List
In other words: a perfect opportunity for a contribution!
--
Cheers,

Michael Hamrah

unread,
May 27, 2015, 3:44:47 PM5/27/15
to Akka User List
;) Thanks for pointing me in the right direction. I'll give it a shot. 

You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/4WvOrFtewQY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Michael Hamrah

unread,
May 28, 2015, 11:30:55 AM5/28/15
to akka...@googlegroups.com, m...@hamrah.com
In researching how to do this I came across akka.stream.io.OutputStreamSink which is exactly what I need: https://github.com/akka/akka/blob/releasing-akka-stream-and-http-experimental-1.0-RC3/akka-stream/src/main/scala/akka/stream/io/OutputStreamSink.scala

The code snippet is very simple:

val outputStream: () => OutputStream = { () => {
 val pipedOutputStream = new PipedOutputStream()
 //do something with the piped output stream, like connect it to a read stream

 //return for later
 pipedOutputStream
}

//somewhere else, maybe in a route:
akkaHttpRequest.entity.getDataBytes.runWith(OutputStreamSink(outputStream), flow)

Reply all
Reply to author
Forward
0 new messages