Created
September 18, 2021 11:07
-
-
Save GaetanoPiazzolla/a6ab4b71b4c7d5420fc6d0a3ab2b065f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.stream.Stream; | |
| import java.util.stream.Collectors; | |
| import java.util.*; | |
| import java.util.regex.Pattern; | |
| private final Pattern pattern = Pattern.compile(SEARCH_TOKEN); | |
| public List<String> searchStreamRegex() { | |
| InputStream inputStream = new FileInputStream(pathFile); | |
| // lazy loading | |
| BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); | |
| Stream<String> linesStream = bufferedReader.lines(); | |
| return linesStream.filter(a -> pattern.matcher(a).find()).collect(Collectors.toList()); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
related to medium article https://gae-piaz.medium.com/search-string-in-file-with-java-as-fast-as-possible-fedafdc7a3ee