Java Socket Address Get parseInetSocketAddress(String address)

Here you can find the source of parseInetSocketAddress(String address)

Description

Parses InetSocketAddress from a String.

License

Apache License

Parameter

Parameter Description
address socket address to parse

Exception

Parameter Description
IOException if the socket address is invalid

Return

InetSocketAddress of the String

Declaration

public static InetSocketAddress parseInetSocketAddress(String address)
        throws IOException 

Method Source Code

//package com.java2s;
/*/*  w  ww.  ja v  a2s  . c  o m*/
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the ?License??). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

import java.io.IOException;

import java.net.InetSocketAddress;

public class Main {
    /**
     * Parses {@link InetSocketAddress} from a String.
     *
     * @param address socket address to parse
     * @return InetSocketAddress of the String
     * @throws IOException if the socket address is invalid
     */
    public static InetSocketAddress parseInetSocketAddress(String address)
            throws IOException {
        if (address == null) {
            return null;
        }
        String[] strArr = address.split(":");
        if (strArr.length != 2) {
            throw new IOException("Invalid InetSocketAddress " + address);
        }
        return new InetSocketAddress(strArr[0], Integer.parseInt(strArr[1]));
    }
}

Related

  1. isUnresolved(SocketAddress address)
  2. isValidMulticastAddress(final InetSocketAddress address)
  3. normalizeInetSocketAddress(InetSocketAddress addr)
  4. normalizeSocketAddr(InetSocketAddress address)
  5. parseAddress(SocketAddress address)
  6. parseInetSocketAddress(String endPoint)
  7. parseInetSocketAddress(String text)
  8. parseSocketAddress(String address)
  9. parseSocketAddress(String addressPort, int defaultPort)