The Artima Developer Community
Sponsored Link

Akka Concurrency Forum
ByteString I/O

6 replies on 1 page. Most recent reply: Mar 29, 2013 2:17 AM by Derek Wyatt

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
Dan Luu

Posts: 27
Nickname: amitra
Registered: Feb, 2013

ByteString I/O Posted: Mar 23, 2013 3:53 PM
Reply to this message Reply
Advertisement
This isn't on the book, per se, but it's related.

After finishing the book, I've been implementing various toy projects. I'll often have some collection of ByteStrings, because akka receives network I/O that way. What's a good (idiomatic and/or clear) way to write ByteStrings to a file?

It seems like I can do something like

Some(new PrintWriter("foo.bar")).foreach{p =>
fileContents.foreach{s => p.write(s.toString)}
}


But, there must be something better than that. There was a brief mention of Camel in the book. Is that something I should look into?


Dan Luu

Posts: 27
Nickname: amitra
Registered: Feb, 2013

Re: ByteString I/O Posted: Mar 23, 2013 8:42 PM
Reply to this message Reply
Whoops. Because I've got binary data, I mean something that uses toArray, not toString. But, either way, it seems wasteful to create a huge data structure just to write some stuff to a file. I suppose I could use toStream.

Derek Wyatt

Posts: 69
Nickname: dwyatt
Registered: Oct, 2012

Re: ByteString I/O Posted: Mar 24, 2013 3:36 AM
Reply to this message Reply
I would take a look at Iteratees. Akka has a simple iteratee implementation that I haven't used personally. I've used Play's a bit here and there, and they have some decent documentation on it, so you might want to try that:

http://www.playframework.com/documentation/2.1.0/Iteratees

Dan Luu

Posts: 27
Nickname: amitra
Registered: Feb, 2013

Re: ByteString I/O Posted: Mar 24, 2013 10:43 AM
Reply to this message Reply
Thanks! Also, thanks again for writing the book. After reading the book, I was able to create a BitTorrent client in about a week, in about 300 lines of scala (including whitespace and comments), despite not having used akka before. It's a bit bigger now, since I've been adding features, but it still seems pretty manageable.

Derek Wyatt

Posts: 69
Nickname: dwyatt
Registered: Oct, 2012

Re: ByteString I/O Posted: Mar 24, 2013 1:56 PM
Reply to this message Reply
Awesome work, Dan! I'm glad you've gotten something out of it, beyond a basic read. Thanks for all the helpful bug reports (seriously :D)

Dan Luu

Posts: 27
Nickname: amitra
Registered: Feb, 2013

Re: ByteString I/O Posted: Mar 28, 2013 12:33 PM
Reply to this message Reply
On a related note (only because it's similarly off-topic), is there any well-written open source akka code you'd recommend looking at? I suppose the akka code itself is probably well written, but I'd like to read some "known" good code.

Derek Wyatt

Posts: 69
Nickname: dwyatt
Registered: Oct, 2012

Re: ByteString I/O Posted: Mar 29, 2013 2:17 AM
Reply to this message Reply
Try Spray. http://spray.io. It's got a lot of next-level type coding in it, which might make it tough to understand, but it's getting some great use out of Akka.

Flat View: This topic has 6 replies on 1 page
Topic: Very low quality of images in MOBI Previous Topic   Next Topic Topic: object scalatest is not a member of package org

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use