Here you can find the source of getSafeInetAddress(String name, JSONObject json)
static InetAddress getSafeInetAddress(String name, JSONObject json)
//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; } }