Example usage for java.net InetSocketAddress getAddress

List of usage examples for java.net InetSocketAddress getAddress

Introduction

In this page you can find the example usage for java.net InetSocketAddress getAddress.

Prototype

public final InetAddress getAddress() 

Source Link

Document

Gets the InetAddress .

Usage

From source file:Main.java

public static void printSocketAddress(InetSocketAddress sAddr) {
    System.out.println("Socket  Address: " + sAddr.getAddress());
    System.out.println("Socket Host  Name: " + sAddr.getHostName());
    System.out.println("Socket Port:  " + sAddr.getPort());
    System.out.println("isUnresolved(): " + sAddr.isUnresolved());
    System.out.println();/*from   w w w. j  ava 2s  . c om*/
}

From source file:ch.epfl.eagle.daemon.util.Network.java

public static THostPort socketAddressToThrift(InetSocketAddress address) {
    return new THostPort(address.getAddress().getHostAddress(), address.getPort());
}

From source file:SocketAddressEncoder.java

public static String encode(InetSocketAddress address) {
    InetAddress servAddr = address.getAddress();
    int servPort = address.getPort();
    return servAddr.getHostAddress().replace('.', ',') + ',' + (servPort >> 8) + ',' + (servPort & 0xFF);
}

From source file:SystemUtils.java

public static final String getRawAddress(InetSocketAddress inetSocketAddress) {
    InetAddress address = inetSocketAddress.getAddress();
    return address != null ? address.getHostAddress() : inetSocketAddress.getHostName();
}

From source file:org.apache.hadoop.util.NodeUtils.java

public static String addressToString(InetSocketAddress addr) {
    InetAddress address = addr.getAddress();
    if (address.isAnyLocalAddress()) {
        //it's local, so patch it to whatever we think we are
        return cachedHostAddress;
    } else {//from   w  w  w . j ava2s  .c o  m
        return addr.getAddress().getHostAddress();
    }
}

From source file:org.stem.utils.Utils.java

public static String extractHostAddr(InetSocketAddress address) {
    if (null != address.getAddress())
        return address.getAddress().getHostAddress();
    else if (null != address.getHostName()) {
        if (address.getHostName().contains("/")) {
            int index = address.getHostName().indexOf("/");
            return address.getHostName().substring(index + 1);
        } else// ww w  .  j av  a  2  s  .co m
            return address.getHostName();
    } else
        throw new RuntimeException("Can not extract ip address");
}

From source file:com.navercorp.pinpoint.plugin.thrift.ThriftUtils.java

/**
 * Returns the ip address retrieved from the given {@link SocketAddress}.
 * //from  w  w w. j a  v  a2  s  . c  o  m
 * @param socketAddress the <tt>SocketAddress</tt> instance to retrieve the ip address from
 * @return the ip address retrieved from the given <tt>socketAddress</tt>,
 *      or {@literal ThriftConstants.UNKNOWN_ADDRESS} if it cannot be retrieved
 */
// TODO should probably be pulled up as a common API
public static String getIp(SocketAddress socketAddress) {
    if (socketAddress == null) {
        return ThriftConstants.UNKNOWN_ADDRESS;
    }
    if (socketAddress instanceof InetSocketAddress) {
        InetSocketAddress addr = (InetSocketAddress) socketAddress;
        return addr.getAddress().getHostAddress();
    }
    return getSocketAddress(socketAddress);
}

From source file:com.navercorp.pinpoint.plugin.thrift.ThriftUtils.java

/**
 * Returns the ip and port information retrieved from the given {@link SocketAddress}.
 * /*w  w  w .j av  a2s.c o m*/
 * @param socketAddress the <tt>SocketAddress</tt> instance to retrieve the ip/port information from
 * @return the ip/port retrieved from the given <tt>socketAddress</tt>,
 *      or {@literal ThriftConstants.UNKNOWN_ADDRESS} if it cannot be retrieved
 */
// TODO should probably be pulled up as a common API
public static String getIpPort(SocketAddress socketAddress) {
    if (socketAddress == null) {
        return ThriftConstants.UNKNOWN_ADDRESS;
    }
    if (socketAddress instanceof InetSocketAddress) {
        InetSocketAddress addr = (InetSocketAddress) socketAddress;
        return addr.getAddress().getHostAddress() + ":" + addr.getPort();
    }
    return getSocketAddress(socketAddress);
}

From source file:org.apache.hadoop.hbase.HServerAddress.java

private static String getBindAddressInternal(InetSocketAddress address) {
    final InetAddress addr = address.getAddress();
    if (addr != null) {
        return addr.getHostAddress();
    } else {//from w w  w. j av  a2  s  . c  o  m
        LogFactory.getLog(HServerAddress.class)
                .error("Could not resolve the" + " DNS name of " + address.getHostName());
        return null;
    }
}

From source file:com.collabnet.tracker.common.httpClient.TrackerHttpSender.java

public static Credentials getCredentials(AuthenticatedProxy authProxy, InetSocketAddress address) {
    return getCredentials(authProxy.getUserName(), authProxy.getPassword(), address.getAddress());
}