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

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

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

Utils.readPropertiesQuietly介绍

[英]Reads properties from a string.
[中]从字符串中读取属性。

代码示例

代码示例来源:origin: net.roboconf/roboconf-agent

/**
 * Creates a new bean from raw properties that will be parsed.
 * @param rawProperties a non-null string
 * @param logger a logger (not null)
 * @return a non-null bean
 * @throws IOException if there were files that failed to be written
 */
public static AgentProperties readIaasProperties( String rawProperties, Logger logger ) throws IOException {
  Properties props = Utils.readPropertiesQuietly( rawProperties, logger );
  return readIaasProperties( props );
}

代码示例来源:origin: net.roboconf/roboconf-dm

@Override
public TargetProperties findTargetProperties( String targetId ) {
  File file = findTargetFile( targetId, Constants.TARGET_PROPERTIES_FILE_NAME );
  String content = Utils.readFileContentQuietly( file, this.logger );
  Map<String,String> map = new HashMap<> ();
  for( Map.Entry<Object,Object> entry : Utils.readPropertiesQuietly( content, this.logger ).entrySet()) {
    map.put((String) entry.getKey(), (String) entry.getValue());
  }
  return new TargetPropertiesImpl( map, content, file );
}

代码示例来源:origin: roboconf/roboconf-platform

/**
 * Loads an application template's descriptor.
 * @param f a file
 * @return an application descriptor (not null)
 * @throws IOException if the file could not be read
 */
public static ApplicationTemplateDescriptor load( File f ) throws IOException {
  // Read the file's content
  String fileContent = Utils.readFileContent( f );
  Logger logger = Logger.getLogger( ApplicationTemplateDescriptor.class.getName());
  Properties properties = Utils.readPropertiesQuietly( fileContent, logger );
  if( properties.get( "fail.read" ) != null )
    throw new IOException( "This is for test purpose..." );
  ApplicationTemplateDescriptor result = load( properties );
  // Resolve line numbers then
  int lineNumber = 1;
  for( String line : fileContent.split( "\n" )) {
    for( String property : ALL_PROPERTIES ) {
      if( line.trim().matches( "(" + LEGACY_PREFIX + ")?" + property + "\\s*[:=].*" )) {
        result.propertyToLine.put( property, lineNumber );
        break;
      }
    }
    lineNumber ++;
  }
  return result;
}

代码示例来源:origin: roboconf/roboconf-platform

@Test
public void testReadProperties() throws Exception {
  // Normal
  Logger logger = Logger.getLogger( getClass().getName());
  String s = "\np1: value1 \\ok\np2 = value2\n\n";
  Properties props = Utils.readPropertiesQuietly( s, logger );
  Assert.assertEquals( 2, props.size());
  Assert.assertEquals( "value1 ok", props.get( "p1" ));
  Assert.assertEquals( "value2", props.get( "p2" ));
  // Null string
  props = Utils.readPropertiesQuietly( null, logger );
  Assert.assertEquals( 0, props.size());
  // Check exceptions
  s = "";
  props = Utils.readPropertiesQuietly( s, logger );
  Assert.assertEquals( 0, props.size());
}

相关文章