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.nio.file.Files; | |
import java.nio.file.Path; | |
private final static String SEARCH_TOKEN = "searchtoken"; | |
public List<String> searchStandard(String pathFile) { | |
List<String> wholeData = Files.readAllLines(Path.of(pathFile)); | |
List<String> found = new ArrayList<>(); | |
for (String wholeDatum : wholeData) { | |
if (wholeDatum.contains(SEARCH_TOKEN)) |
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.*; | |
private final static String SEARCH_TOKEN = "searchtoken"; | |
public List<String> searchScanner() { | |
Path file = Path.of(pathFile); | |
List<String> found = new ArrayList<>(); | |
final Scanner scanner = new Scanner(file); | |
while (scanner.hasNextLine()) { |
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.nio.CharBuffer; | |
import java.nio.MappedByteBuffer; | |
import java.nio.channels.FileChannel; | |
import java.nio.charset.CharsetDecoder; | |
import java.nio.charset.StandardCharsets; | |
public List<String> searchChannel() { | |
CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder(); | |
final FileChannel channel = new FileInputStream(pathFile).getChannel(); | |
MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); |
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.*; | |
public List<String> searchStream() { | |
InputStream inputStream = new FileInputStream(pathFile); | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); | |
Stream<String> linesStream = bufferedReader.lines(); |
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); |
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.*; | |
public List<String> searchStreamParallel() { | |
return Files.readAllLines(Path.of(pathFile)) | |
.parallelStream() | |
.filter(a -> a.contains(SEARCH_TOKEN)) | |
.collect(Collectors.toList()); |
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> searchReactive() { | |
Path ipPath = Path.of(pathFile); | |
return Flux.using( | |
() -> Files.lines(ipPath), | |
Flux::fromStream, | |
Stream::close) |
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), |
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.*; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
import reactor.core.publisher.*; | |
import reactor.core.scheduler.Schedulers; | |
public Flux<String> searchReactiveStream() { | |
return Flux.create((FluxSink<String> fluxSink) -> { |
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.*; | |
import org.apache.commons.lang3.SystemUtils; | |
public List<String> searchSo() { | |
List<String> found = new ArrayList<>(); | |
// apache lang is awesome. | |
if (SystemUtils.IS_OS_WINDOWS) { |