?
for help, space
to navigate
// Get PIDs of own or started processes out.println("Your pid is " + ProcessHandle.current().pid()); Process p = Runtime.getRuntime().exec("sleep 1h"); ProcessHandle h = ProcessHandle.of(p.pid()) // Optional .orElseThrow(IllegalStateException::new); // Do things on exiting process // CompletableFuture h.onExit().thenRun( ()-> out.println("Sleeper exited") ); // Get info on process out.printf("[%d] %s - %s\n", h.pid(), h.info().user().orElse("unknown"), h.info().commandLine().orElse("none")); // Kill a process h.destroy();````
/* Comment sections would break ... */ List<Integer> listOfNumbers = List.of(1, 2, 3, 4, 5/*, null*/); Set<Integer> setOfNumbers = Set.of(1, 2, 3, 4, 5/*, 1*/); Map<String, String> mapOfString = Map.of("key1", "value1", "key2", "value2"); Map<String, String> moreMapOfString = Map.ofEntries( Map.entry("key1", "value1"), Map.entry("key2", "value2")/*, Map.entry("key1", "value3")*/ ); ````
// return class/method only for our classes. private static List<String> walkAndFilterStackframe() { return StackWalker.getInstance().walk(s -> s.map( frame-> frame.getClassName()+"/"+frame.getMethodName()) .filter(name -> name.startsWith("de.exxcellent")) .limit(10) .collect(Collectors.toList()) ); }````
// All bytes from an InputStream at once byte[] result = new ByteArrayInputStream(buf) .readAllBytes(); // Directly redirect an InputStream to an OutputStream new ByteArrayInputStream(buf) .transferTo(System.out);````