Created
February 21, 2014 19:57
-
-
Save zipcode/9142184 to your computer and use it in GitHub Desktop.
This file contains 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
scala> implicit class InputStreamAsString(is: InputStream) { | |
| def asString = { | |
| val buff = new Array[Byte](256) | |
| new String(Iterator.continually({ val c = is.read(buff); buff.take(c)}).takeWhile(_.size>0).flatten.toArray) | |
| } | |
| } | |
defined class InputStreamAsString | |
scala> var s = new ByteArrayInputStream("asdfasdfasdfasdfasdf".getBytes("UTF-8")) | |
s: java.io.ByteArrayInputStream = java.io.ByteArrayInputStream@72c454a | |
scala> s.asString | |
res32: String = asdfasdfasdfasdfasdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment