ayushtkn commented on code in PR #10885:
URL: https://github.com/apache/ozone/pull/10885#discussion_r3668571363


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java:
##########
@@ -228,6 +228,28 @@ public static OptionalInt getHostPort(String value) {
     }
   }
 
+  /**
+   * Extract the host from a host:port address string.
+   * IPv6-aware; accepts bracketed literals such as {@code [2001:db8::1]:9862}.
+   *
+   * @param address address in host:port format
+   * @return the host component without brackets
+   */
+  public static String getHostOnly(String address) {
+    return NetUtils.createSocketAddr(address).getHostString();
+  }
+
+  /**
+   * Extract the port from a host:port address string.
+   * IPv6-aware; accepts bracketed literals such as {@code [2001:db8::1]:9862}.
+   *
+   * @param address address in host:port format
+   * @return the port component as a decimal string
+   */
+  public static String getPort(String address) {
+    return String.valueOf(NetUtils.createSocketAddr(address).getPort());
+  }

Review Comment:
   fundamentally port is an `int`, we should consider the return type as `int`, 
I see we are doing ``Integer.parseInt(getPort(host)));`` at couple of places, I 
would rather convert to `String` if someone requires a `String` rather than 
returning `int` over here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to