Created
July 5, 2011 18:38
-
-
Save xuwei-k/1065522 to your computer and use it in GitHub Desktop.
http GET した結果を、Scala の Iterator[Byte] や Stream[Byte] として取得したい場合
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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