Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.sleepycat.je.rep.utilint;
 
 import java.util.Set;
 
Encapsulates the functionality around dealing with HostPort string pairs having the format: host[:port]
public class HostPortPair {
    static public final String SEPARATOR = ":";

    
Parses a hostPort pair into the socket it represents.

Parameters:
hostPortPair
Returns:
socket address for this host pair
Throws:
java.lang.IllegalArgumentException via ReplicatedEnvironment and Monitor ctors.
    public static InetSocketAddress getSocket(String hostPortPair) {
        if ("".equals(hostPortPair)) {
            throw new IllegalArgumentException
                ("Host and port pair was missing");
        }
        int portStartIndex = hostPortPair.indexOf();
        String hostName = hostPortPair;
        int port = -1;
        if (portStartIndex < 0) {
            port = Integer.parseInt(..getDefault());
        } else {
            hostName = hostPortPair.substring(0, portStartIndex);
            port =
                Integer.parseInt(hostPortPair.substring(portStartIndex+1));
        }
        return new InetSocketAddress(hostNameport);
    }

    
Parses hostPort pairs into sockets it represents.

Parameters:
hostPortPairs
Returns:
a set of socket addresses for these host pairs
    public static Set<InetSocketAddressgetSockets(String hostPortPairs) {
        Set<InetSocketAddresshelpers = new HashSet<InetSocketAddress>();
        for (StringTokenizer tokenizer =
             new StringTokenizer(hostPortPairs",");
             tokenizer.hasMoreTokens();) {
            String hostPortPair = tokenizer.nextToken();
            helpers.add(getSocket(hostPortPair));
        }
        return helpers;
    }
    public static String getString(String hostint port) {
        return host +  + port;
    }

    
Parses and returns the hostname string of a hostport pair
    public static String getHostname(String hostPortPair) {
        int portStartIndex = hostPortPair.indexOf();
        return (portStartIndex < 0) ?
                hostPortPair :
                hostPortPair.substring(0, portStartIndex);
    }

    
Parses and returns the port of a hostport pair
    public static int getPort(String hostPortPair) {
        int portStartIndex = hostPortPair.indexOf();
        return Integer.parseInt((portStartIndex < 0) ?
                                ..getDefault() :
                                hostPortPair.substring(portStartIndex+1));
    }
New to GrepCode? Check out our FAQ X