Rewrite of Pstream in Java instead of Python