Utils.java Source code

Java tutorial

Introduction

Here is the source code for Utils.java

Source

public class Utils {
    /**
     * @param hostStr
     * @param defaultPort
     * @return
     */
    static public int parsePort(String hostStr, int defaultPort) {
        int sepIdx = hostStr.indexOf(':');
        if (sepIdx < 0) {
            return defaultPort;
        } else {
            String portStr = hostStr.substring(sepIdx + 1).trim();
            try {
                return Integer.parseInt(portStr);
            } catch (NumberFormatException e) {
                return defaultPort;
            }
        }
    }
}