Skip to content

Instantly share code, notes, and snippets.

@stk132
Last active April 14, 2020 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stk132/7a30f0e06feb0fed161869652109e795 to your computer and use it in GitHub Desktop.
Save stk132/7a30f0e06feb0fed161869652109e795 to your computer and use it in GitHub Desktop.
scala2.12で呼び出し元でstream closedになるケース
def readGZIPFile[A](filePath: String, proc: String => Option[A]): Either[Throwable, Seq[A]] = {
val gs = new GZIPInputStream(new FileInputStream(filePath))
val ss = Source.fromInputStream(gs, "UTF-8")
try {
val ret = ss.getLines().flatMap(line => proc(line)).toSeq
Right(ret)
} catch {
case NonFatal(t) => Left(t)
} finally {
ss.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment