Grep and LineCount implementations in java