Java InetAddress Create getSafeInetAddress(String name, JSONObject json)

Here you can find the source of getSafeInetAddress(String name, JSONObject json)

Description

get Safe Inet Address

License

Open Source License

Declaration

static InetAddress getSafeInetAddress(String name, JSONObject json) 

Method Source Code

//package com.java2s;
/*/*from w w  w .  jav  a  2s  .  c  om*/
KVM-based Discoverable Cloudlet (KD-Cloudlet) 
Copyright (c) 2015 Carnegie Mellon University.
All Rights Reserved.
    
THIS SOFTWARE IS PROVIDED "AS IS," WITH NO WARRANTIES WHATSOEVER. CARNEGIE MELLON UNIVERSITY EXPRESSLY DISCLAIMS TO THE FULLEST EXTENT PERMITTEDBY LAW ALL EXPRESS, IMPLIED, AND STATUTORY WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF PROPRIETARY RIGHTS.
    
Released under a modified BSD license, please see license.txt for full terms.
DM-0002138
    
KD-Cloudlet includes and/or makes use of the following Third-Party Software subject to their own licenses:
MiniMongo
Copyright (c) 2010-2014, Steve Lacy 
All rights reserved. Released under BSD license.
https://github.com/MiniMongo/minimongo/blob/master/LICENSE
    
Bootstrap
Copyright (c) 2011-2015 Twitter, Inc.
Released under the MIT License
https://github.com/twbs/bootstrap/blob/master/LICENSE
    
jQuery JavaScript Library v1.11.0
http://jquery.com/
Includes Sizzle.js
http://sizzlejs.com/
Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
Released under the MIT license
http://jquery.org/license
*/

import org.json.JSONObject;
import java.net.InetAddress;

public class Main {
    static InetAddress getSafeInetAddress(String name, JSONObject json) {
        String value = getSafeString(name, json);
        if (value == null)
            return null;
        try {
            return InetAddress.getByName(value);
        } catch (Exception e) {
            return null;
        }
    }

    static String getSafeString(String name, JSONObject json) {
        try {
            if (json.has(name)) {
                // We do a null check here because the server will return "null" instead of null
                String val = json.getString(name);
                if (val != null && val.equalsIgnoreCase("null"))
                    val = null;
                return val;
            }
        } catch (Exception e) {

        }
        return null;
    }
}

Related

  1. getNextAvailablePort(InetAddress address, int port)
  2. getOneDotPrefix(InetAddress addr)
  3. getPing(InetAddress address, long timeout)
  4. getPrivateInetInetAddress()
  5. getProtocolFamily(InetAddress address)
  6. getSourceAddressForDestination(InetAddress destination)
  7. getSpecificAddresses(@Nonnull InetAddress in)
  8. getSubnetPrefix(InetAddress ip, int maskLen)
  9. getURI(String protocol, InetAddress host, int port)