Skip to content

Instantly share code, notes, and snippets.

@jto
Forked from playxamplez-admin/CODE
Last active December 20, 2015 03:39
Show Gist options
  • Save jto/6065277 to your computer and use it in GitHub Desktop.
Save jto/6065277 to your computer and use it in GitHub Desktop.
Create an #Enumeratee transforming Bytes in lines. Compose it with am #Iteratee or an #Enumerator
private val LB = "\r\n"
val concatLine: Iteratee[Parsing.MatchInfo[Array[Byte]],String] =
(Enumeratee.breakE[Parsing.MatchInfo[Array[Byte]]](_.isMatch) ><>
Enumeratee.collect{ case Parsing.Unmatched(bytes) => new String(bytes)} &>>
Iteratee.consume()).flatMap(r => Iteratee.head.map(_ => r))
def lineParser =
Enumeratee.map{ s: Array[Byte] =>
(if(s.contains(LB + LB))
Parsing.Matched(s)
else
Parsing.Unmatched(s)): Parsing.MatchInfo[Array[Byte]]
} ><>
Enumeratee.grouped(concatLine) ><>
Enumeratee.filter((s: String) => !s.trim.isEmpty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment