process method in scala
import scala.sys.process._
// An overly complex way of computing size of a compressed file
def gzFileSize(name: String) = {
val cat = Seq("zcat", name)
var count = 0
def byteCounter(input: java.io.InputStream) = {
while(input.read() != -1) count += 1
input.close()
}
val p = cat run new ProcessIO(_.close(), byteCounter, _.close())
p.exitValue()
count
}
// This "fire-and-forgets" the method, which can be lazily read through
// a LazyList[String], and accumulates all errors on a StringBuffer
def sourceFilesAt(baseDir: String): (LazyList[String], StringBuffer) = {
val buffer = new StringBuffer()
val cmd = Seq("find", baseDir, "-name", "*.scala", "-type", "f")
val lazyLines = cmd lazyLines_! ProcessLogger(buffer append _)
(lazyLines, buffer)
}