Example usage for com.google.common.net InetAddresses isInetAddress

List of usage examples for com.google.common.net InetAddresses isInetAddress

Introduction

In this page you can find the example usage for com.google.common.net InetAddresses isInetAddress.

Prototype

public static boolean isInetAddress(String ipString) 

Source Link

Document

Returns true if the supplied string is a valid IP string literal, false otherwise.

Usage

From source file:org.dcache.ftp.door.Help.java

protected InetSocketAddress getExtendedAddressOf(String arg) throws FTPCommandException {
    try {/*from  w w w.  j  av a 2  s. c o  m*/
        checkFTPCommand(!arg.isEmpty(), 501, "Syntax error: empty arguments.");
        ArrayList<String> splitted = Lists.newArrayList(Splitter.on(arg.charAt(0)).split(arg));
        checkFTPCommand(splitted.size() == 5, 501, "Syntax error: Wrong number of arguments in '%s'.", arg);
        Protocol protocol = Protocol.find(splitted.get(1));
        checkFTPCommand(InetAddresses.isInetAddress(splitted.get(2)), 501,
                "Syntax error: '%s' is no valid address.", splitted.get(2));
        InetAddress address = InetAddresses.forString(splitted.get(2));
        checkFTPCommand(protocol.getAddressClass().equals(address.getClass()), 501,
                "Protocol code does not match address: '%s'.", arg);
        int port = Integer.parseInt(splitted.get(3));
        checkFTPCommand(port >= 1 && port <= 65536, 501, "Port number '%d' out of range [1,65536].", port);
        return new InetSocketAddress(address, port);

    } catch (NumberFormatException nfe) {
        throw new FTPCommandException(501, "Syntax error: no valid port number in '" + arg + "'.");
    }
}