Skip to content

Instantly share code, notes, and snippets.

@mocyuto
Last active October 14, 2016 09:50
Show Gist options
  • Save mocyuto/11585376f4741f535365b69d49fdba8f to your computer and use it in GitHub Desktop.
Save mocyuto/11585376f4741f535365b69d49fdba8f to your computer and use it in GitHub Desktop.
inputStream to Seq[String]
import java.io.{ BufferedReader, InputStream, InputStreamReader }
object Input{
/**
* inputStreamで取得したものをカラム数だけ取得
* @return (String列, 途中で切ったか)
*/
protected def stream2string(csvStream: InputStream, lineNumberOp: Option[Int]): (Seq[String], Boolean) = {
val reader = new BufferedReader(new InputStreamReader(csvStream))
var count = -1
val a = Iterator.continually(reader.readLine()).takeWhile { r =>
count += 1
lineNumberOp.forall(_ >= count)
}.toSeq
a.init.filterNot(_ == null) -> (a.last != null)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment