コード例 #1
0
  private InetAddress parseIPv4Address(String host) throws UnknownHostException {
    if (host == null) {
      return null;
    }

    String[] quad = Tokenizer.parseTokens(host, '.');

    if ((quad == null) || (quad.length != 4)) {
      return null;
    }

    byte[] addr = new byte[4];

    for (int i = 0; i < 4; i++) {
      int part = 0;

      if ((quad[i].length() == 0) || (quad[i].length() > 3)) {
        return null;
      }

      for (int k = 0; k < quad[i].length(); k++) {
        char c = quad[i].charAt(k);

        /* No, Character.isDigit is not the same */
        if ((c < '0') || (c > '9')) {
          return null;
        }

        part = part * 10 + (c - '0');
      }

      if (part > 255) /* 300.1.2.3 is invalid =) */ {
        return null;
      }

      addr[i] = (byte) part;
    }

    return InetAddress.getByAddress(host, addr);
  }
コード例 #2
0
 public String[] readNameList() throws IOException {
   return Tokenizer.parseTokens(readString(), ',');
 }