Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.net.*;

import java.util.*;

public class Main {
    /**
     * 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 new LinkedList<InetSocketAddress>(retval);
    }
}