Skip to content
This repository

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

Open
wants to merge 1 commit into from

1 participant

Beckham007
Beckham007

Character.digit(name.charAt(0), 16) != -1 couldn't tell whether is a IP address.
Use Pattern to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

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

Use Pattern to do this.
0e73282
This page is out of date. Refresh to see the latest.
6  src/core/org/apache/hadoop/net/NetUtils.java
@@ -422,6 +422,9 @@ public static void connect(Socket socket,
422 422
     }
423 423
   }
424 424
   
  425
+  private static final Pattern ipPattern = // Pattern for ip
  426
+    Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
  427
+    
425 428
   /** 
426 429
    * Given a string representation of a host, return its ip address
427 430
    * in textual presentation.
@@ -431,7 +434,8 @@ public static void connect(Socket socket,
431 434
    * @return its IP address in the string format
432 435
    */
433 436
   public static String normalizeHostName(String name) {
434  
-    if (Character.digit(name.charAt(0), 16) != -1) { // it is an IP
  437
+//    if (Character.digit(name.charAt(0), 16) != -1) { // it is an IP
  438
+    if (ipPattern.matcher(name).matches()) { // it is an IP
435 439
       return name;
436 440
     } else {
437 441
       try {
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.