Permalink
Browse files

Character.digit(name.charAt(0), 16) != -1 could tell whether is a IP …

…address.

Use Pattern to do this.
  • Loading branch information...
1 parent fcc1cd0 commit 0e73282dc4c83b41e924a79477bc58bff946332f @Beckham007 committed Oct 13, 2011
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/core/org/apache/hadoop/net/NetUtils.java
@@ -422,6 +422,9 @@ public static void connect(Socket socket,
}
}
+ private static final Pattern ipPattern = // Pattern for ip
+ Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
+
/**
* Given a string representation of a host, return its ip address
* in textual presentation.
@@ -431,7 +434,8 @@ public static void connect(Socket socket,
* @return its IP address in the string format
*/
public static String normalizeHostName(String name) {
- if (Character.digit(name.charAt(0), 16) != -1) { // it is an IP
+// if (Character.digit(name.charAt(0), 16) != -1) { // it is an IP
+ if (ipPattern.matcher(name).matches()) { // it is an IP
return name;
} else {
try {

0 comments on commit 0e73282

Please sign in to comment.