Java grep implementation.