Here you can find the source of parsePort(String s)
Parameter | Description |
---|---|
s | - the command string |
static InetSocketAddress parsePort(String s)
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.util.regex.Pattern; public class Main { /**/*from w w w .ja va 2s . co m*/ * Parse the PORT command * @param s - the command string * @return the addr/port pair */ static InetSocketAddress parsePort(String s) { String[] toks = Pattern.compile(",").split(s); byte[] bAddr = new byte[4]; for (int j = 0; j < 4; j++) { bAddr[j] = new Integer(toks[j]).byteValue(); } InetAddress addr = null; try { addr = InetAddress.getByAddress(bAddr); } catch (UnknownHostException exn) { throw new RuntimeException("bad address"); } int portOctet1 = Integer.parseInt(toks[4]); int portOctet2 = Integer.parseInt(toks[5]); if ((portOctet1 < 0) || (portOctet1 > 255) || (portOctet2 < 0) || (portOctet2 > 255)) { throw new RuntimeException("bad port"); } int port = 256 * portOctet1 + portOctet2; return new InetSocketAddress(addr, port); } }