net.roboconf.core.utils.Utils.readUrlContentQuietly()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(2.0k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中net.roboconf.core.utils.Utils.readUrlContentQuietly()方法的一些代码示例,展示了Utils.readUrlContentQuietly()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.readUrlContentQuietly()方法的具体详情如下:
包路径:net.roboconf.core.utils.Utils
类名称:Utils
方法名:readUrlContentQuietly

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 );
}

相关文章