Commit da2b7502 authored by Matteo Melli's avatar Matteo Melli

Check correctly directory name is a pid number

parent 5ba8c0e5
......@@ -56,6 +56,7 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import javax.json.Json;
......@@ -93,7 +94,8 @@ public class Main {
final Map<Integer, ProcessStat> previousStats = new HashMap<>(stats);
Map<Integer, ProcessInfo> processInfoMap = Arrays.asList(new File("/proc").listFiles())
.stream()
.filter(file -> file.getName().charAt(0) >= '0' && file.getName().charAt(0) <= '9')
.filter(file -> IntStream.range(0, file.getName().length())
.allMatch(i -> file.getName().charAt(i) >= '0' && file.getName().charAt(i) <= '9'))
.filter(file -> file.canRead())
.filter(file -> file.isDirectory())
.filter(file -> file.listFiles(entry -> entry.getName().equals("cmdline")).length == 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment