+ public static File getDataHomeDir() {
+ var dataHome = System.getenv("XDG_DATA_HOME");
+ if (dataHome != null) {
+ return new File(dataHome);
+ }
+
+ logger.debug("XDG_DATA_HOME not set, falling back to home dir");
+ return new File(new File(System.getProperty("user.home"), ".local"), "share");
+ }
+
+ public static File getRuntimeDir() {
+ var runtimeDir = System.getenv("XDG_RUNTIME_DIR");
+ if (runtimeDir != null) {
+ return new File(runtimeDir);
+ }
+
+ logger.debug("XDG_RUNTIME_DIR not set, falling back to temp dir");
+ return new File(System.getProperty("java.io.tmpdir"));
+ }
+
+ public static Supplier<String> getLineSupplier(final Reader reader) {
+ final var bufferedReader = new BufferedReader(reader);
+ return () -> {
+ try {
+ return bufferedReader.readLine();
+ } catch (IOException e) {
+ logger.error("Error occurred while reading line", e);
+ return null;
+ }
+ };
+ }
+
+ public static InetSocketAddress parseInetSocketAddress(final String tcpAddress) throws UserErrorException {
+ final var colonIndex = tcpAddress.lastIndexOf(':');
+ if (colonIndex < 0) {
+ throw new UserErrorException("Invalid tcp bind address (expected host:port): " + tcpAddress);
+ }
+ final var host = tcpAddress.substring(0, colonIndex);
+ final var portString = tcpAddress.substring(colonIndex + 1);
+
+ final int port;
+ try {
+ port = Integer.parseInt(portString);
+ } catch (NumberFormatException e) {
+ throw new UserErrorException("Invalid tcp port: " + portString, e);
+ }
+ final var socketAddress = new InetSocketAddress(host, port);
+ if (socketAddress.isUnresolved()) {
+ throw new UserErrorException("Invalid tcp bind address, invalid host: " + host);
+ }
+ return socketAddress;
+ }
+
+ public static UnixDomainPrincipal getUnixDomainPrincipal(final SocketChannel channel) throws IOException {
+ UnixDomainPrincipal principal = null;