Created
March 13, 2015 07:28
-
-
Save wookietreiber/ed439fd7958b6d67eeb4 to your computer and use it in GitHub Desktop.
Scala StringInputStream: have a String and read from it with an InputStream
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
import java.io.InputStream | |
class StringInputStream(s: String) extends InputStream { | |
private val bytes = s.getBytes | |
private var pos = 0 | |
override def read(): Int = if (pos >= bytes.length) { | |
-1 | |
} else { | |
val r = bytes(pos) | |
pos += 1 | |
r.toInt | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment