Skip to content

Instantly share code, notes, and snippets.

@GaetanoPiazzolla
Created September 18, 2021 10:58
Show Gist options
  • Select an option

  • Save GaetanoPiazzolla/f56b82733ea62e0e0b6e3ce757ed0f47 to your computer and use it in GitHub Desktop.

Select an option

Save GaetanoPiazzolla/f56b82733ea62e0e0b6e3ce757ed0f47 to your computer and use it in GitHub Desktop.
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());
CharBuffer decodedBuffer = decoder.decode(buffer);
String[] a = decodedBuffer.toString().split("\n");
List<String> found = new ArrayList<>();
for (String s : a) {
if (s.contains(SEARCH_TOKEN)) {
found.add(s);
}
}
return found;
}
@GaetanoPiazzolla

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment