For the first problem, you can start a new thread that starts this method after sleep for a set period of time or until it has some entries (do Runnable with a mailbox to get a map) - if you do not need to use a map directly, then I think the only way is to wait for the recordings. For example (if you need to use the card directly):
public Map<String, String> createArpMap() throws IOException { checkMapARP.clear(); BufferedReader localBufferdReader = new BufferedReader(new FileReader(new File("/proc/net/arp"))); String line = ""; while ((line = localBufferdReader.readLine()) == null) { localBufferdReader.close(); Thread.sleep(1000); localBufferdReader = new BufferedReader(new FileReader(new File("/proc/net/arp"))); } do { String[] ipmac = line.split("[ ]+"); if (!ipmac[0].matches("IP")) { String ip = ipmac[0]; String mac = ipmac[3]; if (!checkMapARP.containsKey(ip)) { checkMapARP.put(ip, mac); } } } while ((line = localBufferdReader.readLine()) != null); return Collections.unmodifiableMap(checkMapARP); }
ddmps source share