/**
 * 
 */
package cn.strong.fastdfs.utils;

import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Tracker 地址帮助类
 * 
 * @author liulongbiao
 *
 */
public class TrackerAddress {

	static final String DFT_HOST = "127.0.0.1";
	static final int DFT_PORT = 22122;
	static final List<InetSocketAddress> DFT_ADDRS = Collections.unmodifiableList(Arrays
			.asList(new InetSocketAddress(DFT_HOST, DFT_PORT)));

	/**
	 * 解析 Tracker 地址
	 * 
	 * @param uris
	 *            以逗号分隔的地址
	 * @return 网络地址列表
	 */
	public static List<InetSocketAddress> parseTrackers(String uris) {
		if (uris == null) {
			return DFT_ADDRS;
		}
		uris = uris.trim();
		if (uris.isEmpty()) {
			return DFT_ADDRS;
		}
		List<InetSocketAddress> result = new ArrayList<>();
		for (String uri : uris.split(",")) {
			result.add(parseTrackerUri(uri));
		}
		return result;
	}

	private static InetSocketAddress parseTrackerUri(String uri) {
		String host = DFT_HOST;
		int port = DFT_PORT;
		if (uri.startsWith("[")) {
			int idx = uri.indexOf("]");
			if (idx == -1) {
				throw new IllegalArgumentException(
						"an IPV6 address must be encosed with '[' and ']' according to RFC 2732.");
			}
			int portIdx = uri.indexOf("]:");
			if (portIdx != -1) {
				port = Integer.parseInt(uri.substring(portIdx + 2));
			}
			host = uri.substring(1, idx);
		} else {
			int idx = uri.indexOf(":");
			if (idx > 0) {
				try {
					port = Integer.parseInt(uri.substring(idx + 1));
				} catch (NumberFormatException e) {
					throw new IllegalArgumentException(
							"host and port should be specified in host:port format");
				}
				host = uri.substring(0, idx).trim();
			} else {
				host = uri;
			}
		}
		return new InetSocketAddress(host, port);
	}
}

@@ -491,16 +491,510 @@
 RT)));%0A%0A
+%09/**%0A%09 * %E5%88%9B%E5%BB%BA tracker %E7%A7%8D%E5%AD%90%EF%BC%8C%E9%BB%98%E8%AE%A4%E9%A1%BA%E5%BA%8F%E9%80%89%E5%8F%96%E7%AD%96%E7%95%A5%0A%09 * %0A%09 * @param uris%0A%09 * @return Tracker %E5%9C%B0%E5%9D%80%E7%A7%8D%E5%AD%90%0A%09 */%0A%09public static Seed%3CInetSocketAddress%3E createSeed(String uris) %7B%0A%09%09return createSeed(uris);%0A%09%7D%0A%0A%09/**%0A%09 * %E5%88%9B%E5%BB%BA tracker %E7%A7%8D%E5%AD%90%0A%09 * %0A%09 * @param uris%0A%09 *            %E4%BB%A5%E9%80%97%E5%8F%B7%E5%88%86%E9%9A%94%E7%9A%84%E5%9C%B0%E5%9D%80%0A%09 * @param strategy%0A%09 *            %E9%80%89%E5%8F%96%E7%AD%96%E7%95%A5%0A%09 * @return Tracker %E5%9C%B0%E5%9D%80%E7%A7%8D%E5%AD%90%0A%09 */%0A%09public static Seed%3CInetSocketAddress%3E createSeed(String uris, int strategy) %7B%0A%09%09List%3CInetSocketAddress%3E addrs = parseTrackers(uris);%0A%09%09return Seed.create(addrs, strategy);%0A%09%7D%0A%0A
 %09/**%0A%09 *

add createSeed