本文整理了Java中net.roboconf.core.utils.Utils.readUrlContentQuietly()
方法的一些代码示例,展示了Utils.readUrlContentQuietly()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.readUrlContentQuietly()
方法的具体详情如下:
包路径:net.roboconf.core.utils.Utils
类名称:Utils
方法名:readUrlContentQuietly
[英]Reads the content of an URL (assumed to be text content).
[中]读取URL的内容(假定为文本内容)。
代码示例来源:origin: net.roboconf/roboconf-agent
/**
* Configures the agent from a IaaS registry.
* @param logger a logger
* @return the agent's data, or null if they could not be parsed
*/
public AgentProperties findParametersForAmazonOrOpenStack( Logger logger ) {
logger.info( "User data are being retrieved for AWS / Openstack..." );
// Copy the user data
String userData = Utils.readUrlContentQuietly( "http://169.254.169.254/latest/user-data", logger );
String ip = Utils.readUrlContentQuietly( "http://169.254.169.254/latest/meta-data/public-ipv4", logger );
AgentProperties result = null;
try {
// Parse the user data
result = AgentProperties.readIaasProperties( userData, logger );
// Verify the IP
if( ! AgentUtils.isValidIP( ip )) {
// Failed retrieving public IP: try private one instead
ip = Utils.readUrlContentQuietly( "http://169.254.169.254/latest/meta-data/local-ipv4", logger );
}
if( AgentUtils.isValidIP( ip ))
result.setIpAddress( ip );
else
logger.severe( "No IP address could be retrieved (either public-ipv4 or local-ipv4)." );
} catch( IOException e ) {
logger.severe( "The network properties could not be read. " + e.getMessage());
Utils.logException( logger, e );
}
return result;
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testReadUrlContent() throws Exception {
File f = this.folder.newFile();
Utils.writeStringInto( "kikou", f );
String readContent = Utils.readUrlContent( f.toURI().toURL().toString());
Assert.assertEquals( "kikou", readContent );
Utils.deleteFilesRecursively( f );
Assert.assertFalse( f.exists());
Logger logger = Logger.getLogger( getClass().getName());
readContent = Utils.readUrlContentQuietly( f.toURI().toURL().toString(), logger );
Assert.assertEquals( "", readContent );
}
内容来源于网络,如有侵权,请联系作者删除!