-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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