grep implementation in java