I've actually looked at this option and tried to see if I can use some kind of pipes for this but couldn't find a good and simple solution (but frankly I don't have any experience with java and the available modules, so there must be something I missed). 
Going that route though will make the code different enough that it may require a split into a different class.