Skip to content

Instantly share code, notes, and snippets.

@wookietreiber
Last active August 29, 2015 14:17
Show Gist options
  • Save wookietreiber/15238bcd230c18cf1726 to your computer and use it in GitHub Desktop.
Save wookietreiber/15238bcd230c18cf1726 to your computer and use it in GitHub Desktop.
Scala StringOutputStream: feed an OutputStream and retrieve the data as a String
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