Skip to content

Instantly share code, notes, and snippets.

View GaetanoPiazzolla's full-sized avatar
☠️
Sleep is for those without deadlines

Gaetano Piazzolla GaetanoPiazzolla

☠️
Sleep is for those without deadlines
View GitHub Profile
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))
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()) {
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());
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();
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);
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());
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)
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),
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) -> {
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) {