Last active
August 29, 2015 14:17
-
-
Save wookietreiber/15238bcd230c18cf1726 to your computer and use it in GitHub Desktop.
Scala StringOutputStream: feed an OutputStream and retrieve the data as a String
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.OutputStream | |
class StringOutputStream extends OutputStream { | |
private val bytes = collection.mutable.ArrayBuffer[Byte]() | |
override def write(b: Int): Unit = { | |
bytes += b.toByte | |
} | |
def s: String = new String(bytes.toArray) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment