How to transform streams and consume them
As mentioned before, a Source is responsible for consuming elements and emitting them through the stream. A Flow is responsible for transforming elements as they go. In this recipe, we will revisit the out-of-the-box transforming functions a Flow provides. In a later recipe, we will see how we can create more complicated Flows using the Graph DSL.
Getting ready
We will use the same prerequisites as that of the previous recipe. This time, we will implement a stream to do a word count. We will consume a GZIP compressed file and count the occurrences of each word.
How to do it...
For this recipe, perform the following steps:
- Create a test file named
gzipped-file
insidesrc/main/resources
with the following contents:
hello world from akka streams! No seriously, HELLO WORLD FROM AKKA STREAMS!!!
- Then compress the file. This can be easily achieved using the
gzip gzipped-file
command. You should end up with a compressed file namedgzipped-file.gz...