Created
September 18, 2021 11:37
-
-
Save GaetanoPiazzolla/5a8186355f7a0ccc1e2ab41b0c106426 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 reactor.core.publisher.*; | |
| import java.nio.file.Path; | |
| public Flux<String> searchReactiveParallel(Integer buffer, Integer threads) { | |
| Path ipPath = Path.of(pathFile); | |
| if (buffer == null) | |
| return Flux.using( | |
| () -> Files.lines(ipPath), | |
| Flux::fromStream, | |
| Stream::close) | |
| .subscribeOn(Schedulers.newParallel("searchReactive2", threads)) | |
| .share() | |
| .filter(l -> l.contains(SEARCH_TOKEN)) | |
| .map(s -> s + "\r\n"); | |
| else | |
| return Flux.using( | |
| () -> Files.lines(ipPath), | |
| Flux::fromStream, | |
| Stream::close) | |
| .subscribeOn(Schedulers.newParallel("searchReactive2", threads)) | |
| .share() | |
| .buffer(buffer) | |
| .flatMap(l -> Flux.fromStream( | |
| l.stream().filter(line -> line.contains(SEARCH_TOKEN)).map(s -> s + "\r\n") | |
| ) | |
| ); | |
| } |
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