Java HTTP Port Find parseCommaDelimitedHosts2(String hosts, int port_range)

Here you can find the source of parseCommaDelimitedHosts2(String hosts, int port_range)

Description

Input is "daddy[8880],sindhu[8880],camille[5555].

License

LGPL

Declaration

public static List<InetSocketAddress> parseCommaDelimitedHosts2(String hosts, int port_range) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.net.*;

import java.util.*;

public class Main {
    /**//from   w w w  .j av  a  2  s.c  om
     * Input is "daddy[8880],sindhu[8880],camille[5555]. Return List of
     * InetSocketAddress
     */
    public static List<InetSocketAddress> parseCommaDelimitedHosts2(String hosts, int port_range) {

        StringTokenizer tok = new StringTokenizer(hosts, ",");
        String t;
        InetSocketAddress addr;
        Set<InetSocketAddress> retval = new HashSet<InetSocketAddress>();

        while (tok.hasMoreTokens()) {
            t = tok.nextToken().trim();
            String host = t.substring(0, t.indexOf('['));
            host = host.trim();
            int port = Integer.parseInt(t.substring(t.indexOf('[') + 1, t.indexOf(']')));
            for (int i = port; i < port + port_range; i++) {
                addr = new InetSocketAddress(host, i);
                retval.add(addr);
            }
        }
        return Collections.unmodifiableList(new LinkedList<InetSocketAddress>(retval));
    }
}

Related

  1. isTcpPortOpenCallable(final int port)
  2. isTcpPortOpenCallable(final int port)
  3. loadStringSupportedType(String javaType)
  4. parse(final String desc, final int defaultPort)
  5. parse(String specs, int defaultPort)
  6. parseHostPort(String s)
  7. parsePort(String s)
  8. ping(String domain, int port)
  9. pingServer(String host, Integer port)