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

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

Introduction

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

Prototype

public static String toAddrString(InetAddress ip) 

Source Link

Document

Returns the string representation of an InetAddress .

Usage

From source file:io.airlift.node.NodeInfo.java

public NodeInfo(String environment, String pool, String nodeId, InetAddress internalIp, InetAddress bindIp,
        String externalAddress, String location, String binarySpec, String configSpec) {
    checkNotNull(environment, "environment is null");
    checkNotNull(pool, "pool is null");
    checkArgument(environment.matches(NodeConfig.ENV_REGEXP), "environment '%s' is invalid", environment);
    checkArgument(pool.matches(NodeConfig.POOL_REGEXP), "pool '%s' is invalid", pool);

    this.environment = environment;
    this.pool = pool;

    if (nodeId != null) {
        checkArgument(nodeId.matches(NodeConfig.ID_REGEXP), "nodeId '%s' is invalid", nodeId);
        this.nodeId = nodeId;
    } else {//from  w  ww  . j  a  v  a  2 s  .c  o  m
        this.nodeId = UUID.randomUUID().toString();
    }

    if (location != null) {
        this.location = location;
    } else {
        this.location = "/" + this.nodeId;
    }

    this.binarySpec = binarySpec;
    this.configSpec = configSpec;

    if (internalIp != null) {
        this.internalIp = internalIp;
    } else {
        this.internalIp = findPublicIp();
    }

    if (bindIp != null) {
        this.bindIp = bindIp;
    } else {
        this.bindIp = InetAddresses.fromInteger(0);
    }

    if (externalAddress != null) {
        this.externalAddress = externalAddress;
    } else {
        this.externalAddress = InetAddresses.toAddrString(this.internalIp);
    }
}

From source file:org.apache.flink.util.NetUtils.java

/**
 * Encodes an IP address properly as a URL string. This method makes sure that IPv6 addresses
 * have the proper formatting to be included in URLs.
 * <p>//from w  ww .j a v a2  s.c om
 * This method internally uses Guava's functionality to properly encode IPv6 addresses.
 * 
 * @param address The IP address to encode.
 * @return The proper URL string encoded IP address.
 */
public static String ipAddressToUrlString(InetAddress address) {
    if (address == null) {
        throw new NullPointerException("address is null");
    } else if (address instanceof Inet4Address) {
        return address.getHostAddress();
    } else if (address instanceof Inet6Address) {
        return '[' + InetAddresses.toAddrString(address) + ']';
    } else {
        throw new IllegalArgumentException("Unrecognized type of InetAddress: " + address);
    }
}

From source file:org.apache.directory.server.dhcp.service.AbstractDhcpReplyFactory.java

/** Utility: Sets the ServerIdentifier option in the reply. */
protected static void setServerIdentifier(@Nonnull DhcpMessage reply, @Nonnull InetAddress localAddress) {
    if (!AddressUtils.isZeroAddress(localAddress)) {
        reply.setServerHostname(InetAddresses.toAddrString(localAddress));
        reply.getOptions().add(new ServerIdentifier(localAddress));
    }/*from w  ww .jav a  2  s  .c om*/
}

From source file:com.facebook.presto.type.IpAddressOperators.java

@ScalarOperator(CAST)
@SqlType(StandardTypes.VARCHAR)/*  www .  j  a  v  a2s  .co  m*/
public static Slice castFromIpAddressToVarchar(@SqlType(StandardTypes.IPADDRESS) Slice slice) {
    try {
        return utf8Slice(InetAddresses.toAddrString(InetAddress.getByAddress(slice.getBytes())));
    } catch (UnknownHostException e) {
        throw new PrestoException(INVALID_CAST_ARGUMENT, "Invalid IP address binary length: " + slice.length(),
                e);
    }
}

From source file:org.ftccommunity.enigmabot.LaunchActivity.java

@Override
public void onStart() {
    super.onStart();
    final TextView ipAddressLabel = (TextView) findViewById(R.id.IpAddressValue);

    while (currentAddress == null) {
        try {/*  w  w w . j  a va 2 s.c  om*/
            synchronized (this) {
                this.wait();
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
    ipAddressLabel.setText(InetAddresses.toAddrString(currentAddress));

    Intent intent = new Intent(this, RobotService.class);
    bindService(intent, connection, BIND_AUTO_CREATE);
}

From source file:com.gemini.discover.nmap.DiscoveryProviderNmapImpl.java

@Override
public List<Host> discoverSingleNetwork(GeminiNetwork network) {
    //build the network for nmap
    String nmapCmd = "";

    if (network.isDiscovered()) {
        //no hosts to discover
        Logger.error("NMAP Discovery: Network already discovered - reset flag and try again");
        return null;
    }/*from ww  w.ja v  a 2 s.  com*/

    //parse the discovery network from the network object... it can be one or all of the 
    //start/end, network/mask and host
    String start = InetAddresses.toAddrString(network.getStart());
    String end = InetAddresses.toAddrString(network.getEnd());
    if (!start.isEmpty() && !end.isEmpty()) {
        //get the last three letters of the end string
        List<String> splits = Splitter.on(".").splitToList(end);
        nmapCmd += start + "-" + splits.get(splits.size() - 1);
    }

    String net = InetAddresses.toAddrString(network.getNetwork());
    String mask = String.valueOf(network.getMask());
    if (!net.isEmpty() && network.getMask() > MIN_NETWORK_MASK) {
        if (!nmapCmd.isEmpty()) {
            nmapCmd += ",";
        }
        nmapCmd += net + "/" + mask;
    }

    String host = network.getHost();
    if (!host.isEmpty()) {
        if (!nmapCmd.isEmpty()) {
            nmapCmd += ",";
        }
        nmapCmd += host;
    }

    if (nmapCmd.isEmpty()) {
        //no hosts to discover
        Logger.error("NMAP Discovery: No hosts to discover");
        return null;
    }

    NMap nmap = new NMap();
    try {
        //run the nmap.run command, returns a list of hosts
        return nmap.runCommand(nmapCmd);
    } catch (IOException | InterruptedException | ParserConfigurationException | SAXException ex) {
        Logger.error("NMAP Discovery failed: {}", ex.toString());
        return null;
    }
}

From source file:org.opendaylight.controller.sal.compatibility.FromSalConversionsUtils.java

@SuppressWarnings("unused")
private static Address addressFromAction(InetAddress inetAddress) {
    String strInetAddresss = InetAddresses.toAddrString(inetAddress);
    if (inetAddress instanceof Inet4Address) {
        Ipv4Builder ipv4Builder = new Ipv4Builder();
        ipv4Builder.setIpv4Address(new Ipv4Prefix(strInetAddresss));
        return ipv4Builder.build();
    } else if (inetAddress instanceof Inet6Address) {
        Ipv6Builder ipv6Builder = new Ipv6Builder();
        ipv6Builder.setIpv6Address(new Ipv6Prefix(strInetAddresss));
        return ipv6Builder.build();
    }//  ww w  .ja  v a  2 s .com
    return null;
}

From source file:org.opendaylight.protocol.bmp.impl.app.BmpRouterImpl.java

@Override
public void onSessionUp(final BmpSession session) {
    this.session = session;
    this.routerIp = InetAddresses.toAddrString(this.session.getRemoteAddress());
    this.routerId = new RouterId(Ipv4Util.getIpAddress(this.session.getRemoteAddress()));
    // check if this session is redundant
    if (!this.sessionManager.addSessionListener(this)) {
        LOG.warn(/*from  w  w w .  j  av  a 2 s. c om*/
                "Redundant BMP session with remote router {} ({}) detected. This BMP session will be abandoned.",
                this.routerIp, this.session);
        this.close();
    } else {
        this.routerYangIId = YangInstanceIdentifier.builder(this.sessionManager.getRoutersYangIId())
                .nodeWithKey(Router.QNAME, ROUTER_ID_QNAME, this.routerIp).build();
        this.peersYangIId = YangInstanceIdentifier.builder(routerYangIId).node(Peer.QNAME).build();
        createRouterEntry();
        LOG.info("BMP session with remote router {} ({}) is up now.", this.routerIp, this.session);
    }
}

From source file:org.kairosdb.core.CoreModule.java

@SuppressWarnings("unchecked")
@Override/*  w w w .jav  a 2  s  .c  om*/
protected void configure() {
    bind(QueryQueuingManager.class).in(Singleton.class);
    bind(KairosDatastore.class).in(Singleton.class);
    bind(AggregatorFactory.class).to(GuiceAggregatorFactory.class).in(Singleton.class);
    bind(GroupByFactory.class).to(GuiceGroupByFactory.class).in(Singleton.class);
    bind(QueryPluginFactory.class).to(GuiceQueryPluginFactory.class).in(Singleton.class);
    bind(QueryParser.class).in(Singleton.class);
    bind(CacheFileCleaner.class).in(Singleton.class);
    bind(KairosDBScheduler.class).in(Singleton.class);
    bind(MemoryMonitor.class).in(Singleton.class);

    bind(SumAggregator.class);
    bind(MinAggregator.class);
    bind(MaxAggregator.class);
    bind(AvgAggregator.class);
    bind(StdAggregator.class);
    bind(RateAggregator.class);
    bind(SamplerAggregator.class);
    bind(LeastSquaresAggregator.class);
    bind(PercentileAggregator.class);
    bind(DivideAggregator.class);
    bind(ScaleAggregator.class);
    bind(CountAggregator.class);
    bind(DiffAggregator.class);
    bind(DataGapsMarkingAggregator.class);
    bind(FirstAggregator.class);
    bind(LastAggregator.class);
    bind(SaveAsAggregator.class);
    bind(TrimAggregator.class);

    bind(ValueGroupBy.class);
    bind(TimeGroupBy.class);
    bind(TagGroupBy.class);
    bind(BinGroupBy.class);

    Names.bindProperties(binder(), m_props);
    bind(Properties.class).toInstance(m_props);

    String hostname = m_props.getProperty("kairosdb.hostname");
    bindConstant().annotatedWith(Names.named("HOSTNAME")).to(hostname != null ? hostname : Util.getHostName());

    bind(new TypeLiteral<List<DataPointListener>>() {
    }).toProvider(DataPointListenerProvider.class);

    //bind datapoint default impls
    bind(DoubleDataPointFactory.class).to(getClassForProperty(DATAPOINTS_FACTORY_DOUBLE)).in(Singleton.class);
    //This is required in case someone overwrites our factory property
    bind(DoubleDataPointFactoryImpl.class).in(Singleton.class);

    bind(LongDataPointFactory.class).to(getClassForProperty(DATAPOINTS_FACTORY_LONG)).in(Singleton.class);
    //This is required in case someone overwrites our factory property
    bind(LongDataPointFactoryImpl.class).in(Singleton.class);

    bind(LegacyDataPointFactory.class).in(Singleton.class);

    bind(StringDataPointFactory.class).in(Singleton.class);

    bind(StringDataPointFactory.class).in(Singleton.class);

    bind(NullDataPointFactory.class).in(Singleton.class);

    bind(KairosDataPointFactory.class).to(GuiceKairosDataPointFactory.class).in(Singleton.class);

    String hostIp = m_props.getProperty("kairosdb.host_ip");
    bindConstant().annotatedWith(Names.named("HOST_IP"))
            .to(hostIp != null ? hostIp : InetAddresses.toAddrString(Util.findPublicIp()));
}

From source file:org.opendaylight.protocol.pcep.pcc.mock.PCCTunnelManagerImpl.java

public PCCTunnelManagerImpl(final int lspsCount, final InetAddress address, final int redelegationTimeout,
        final int stateTimeout, final Timer timer, final Optional<TimerHandler> timerHandler) {
    Preconditions.checkArgument(lspsCount >= 0);
    this.redelegationTimeout = redelegationTimeout;
    this.stateTimeout = stateTimeout;
    this.plspIDsCounter = new AtomicLong(lspsCount);
    this.address = InetAddresses.toAddrString(Preconditions.checkNotNull(address));
    this.timer = Preconditions.checkNotNull(timer);
    this.timerHandler = timerHandler;
    this.lspsCount = lspsCount;
}