private void writePantheonPortsToFile() {
final Properties properties = new Properties();
if (networkRunner.getNetwork().isListening()) {
properties.setProperty("discovery", String.valueOf(getP2pUdpPort()));
properties.setProperty("p2p", String.valueOf(getP2pTcpPort()));
}
if (getJsonRpcPort().isPresent()) {
properties.setProperty("json-rpc", String.valueOf(getJsonRpcPort().get()));
}
if (getWebsocketPort().isPresent()) {
properties.setProperty("ws-rpc", String.valueOf(getWebsocketPort().get()));
}
if (getMetricsPort().isPresent()) {
properties.setProperty("metrics", String.valueOf(getMetricsPort().get()));
}
final File portsFile = new File(dataDir.toFile(), "pantheon.ports");
portsFile.deleteOnExit();
try (final FileOutputStream fileOutputStream = new FileOutputStream(portsFile)) {
properties.store(
fileOutputStream,
"This file contains the ports used by the running instance of Pantheon. This file will be deleted after the node is shutdown.");
} catch (final Exception e) {
LOG.warn("Error writing ports file", e);
}
}