Java code for matching and searching patterns in text file