Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created July 5, 2011 18:38
Show Gist options
  • Save xuwei-k/1065522 to your computer and use it in GitHub Desktop.
Save xuwei-k/1065522 to your computer and use it in GitHub Desktop.
http GET した結果を、Scala の Iterator[Byte] や Stream[Byte] として取得したい場合
def byteIteratorFromURL(url:String):Iterator[Byte] = {
val in = new java.net.URL(url).openStream
Iterator.continually(in.read).takeWhile(_ != -1).map(_.toByte)
}
def byteStreamFromURL(url:String):Stream[Byte] = {
val in = new java.net.URL(url).openStream
Stream.continually(in.read).takeWhile(_ != -1).map(_.toByte)
}
// todo close ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment