Last active
September 18, 2021 16:32
-
-
Save GaetanoPiazzolla/04eb58ebe7e5abbc866cefb326dce500 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.*; | |
| import org.apache.commons.lang3.SystemUtils; | |
| public List<String> searchSo() { | |
| List<String> found = new ArrayList<>(); | |
| // apache lang is awesome. | |
| if (SystemUtils.IS_OS_WINDOWS) { | |
| ProcessBuilder builder = new ProcessBuilder( | |
| "cmd.exe", "/c", "findstr " + SEARCH_TOKEN + " c:\\temp\\big.txt"); | |
| builder.redirectErrorStream(true); | |
| Process p = builder.start(); | |
| BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); | |
| String line; | |
| while (true) { | |
| line = r.readLine(); | |
| if (line == null) { | |
| break; | |
| } | |
| found.add(line); | |
| } | |
| } else if (SystemUtils.IS_OS_LINUX) { | |
| // well. do the same thing but with grep LOL | |
| } else { | |
| logger.error("So not supported."); | |
| } | |
| return found; | |
| } |
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