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

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

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

Utils.writeStringInto介绍

[英]Writes a string into a file.
[中]将字符串写入文件。

代码示例

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

@Override
  protected File writeFileContent( String fileContent ) throws IOException {

    File targetFile = new File( this.outputDirectory, "index.md" );
    Utils.createDirectory( targetFile.getParentFile());
    Utils.writeStringInto( fileContent.replaceAll( "\n{3,}", "\n\n" ), targetFile );

    return targetFile;
  }
}

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

@Override
  protected File writeFileContent( String fileContent ) throws IOException {

    File targetFile = new File( this.outputDirectory, "index.md" );
    Utils.createDirectory( targetFile.getParentFile());
    Utils.writeStringInto( fileContent.replaceAll( "\n{3,}", "\n\n" ), targetFile );

    return targetFile;
  }
}

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

@Override
public void createOrUpdateCommand( Application app, String commandName, String commandText ) throws IOException {
  File cmdFile = findCommandFile( app, commandName );
  Utils.createDirectory( cmdFile.getParentFile());
  Utils.writeStringInto( commandText, cmdFile );
}

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

@Override
  public void execute() throws CommandException {

    try {
      File f = new File( this.instr.getFilePath());
      Utils.writeStringInto( this.instr.getContent(), f );

    } catch( IOException e ) {
      throw new CommandException( e );
    }
  }
}

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

@Test
public void testParseDirectory_ok() throws Exception {
  File dir = this.folder.newFolder();
  Utils.writeStringInto( "id: tid1\nhandler: in\nname: na", new File( dir, "t1.properties" ));
  Utils.writeStringInto( "id: tid2\nhandler: in\nname: na", new File( dir, "t2.properties" ));
  List<ModelError> errors = TargetValidator.parseDirectory( dir );
  Assert.assertEquals( 0, errors.size());
}

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

@Test
public void testParseDirectory_conflictingIds() throws Exception {
  File dir = this.folder.newFolder();
  Utils.writeStringInto( "id: tid\nhandler: in\nname: na", new File( dir, "t1.properties" ));
  Utils.writeStringInto( "id: tid\nhandler: in\nname: na", new File( dir, "t2.properties" ));
  List<ModelError> errors = TargetValidator.parseDirectory( dir );
  Assert.assertEquals( 1, errors.size());
  Assert.assertEquals( ErrorCode.REC_TARGET_CONFLICTING_ID, errors.get( 0 ).getErrorCode());
}

代码示例来源: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 );
}

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

@Test
public void testReadFileContentQuietly() throws Exception {
  String s = "this is\na\test\t";
  File output = this.folder.newFile();
  Utils.writeStringInto( s, output );
  String readS = Utils.readFileContentQuietly( output, Logger.getLogger( getClass().getName()));
  Assert.assertEquals( s, readS );
}

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

@Test
public void testInvalidExternalExports_2() throws Exception {
  File f = this.folder.newFile();
  Utils.writeStringInto( "exports: HAProxy.ip as lb-ip HAProxy.httpPort as lb-port", f );
  ApplicationTemplateDescriptor desc = ApplicationTemplateDescriptor.load( f );
  Assert.assertEquals( 0, desc.externalExports.size());
  Assert.assertEquals( 1, desc.invalidExternalExports.size());
  Assert.assertEquals( "HAProxy.ip as lb-ip HAProxy.httpPort as lb-port", desc.invalidExternalExports.iterator().next());
}

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

@Test
public void testInvalidExternalExports_1() throws Exception {
  File f = this.folder.newFile();
  Utils.writeStringInto( "exports = toto IS titi", f );
  ApplicationTemplateDescriptor desc = ApplicationTemplateDescriptor.load( f );
  Assert.assertEquals( 0, desc.externalExports.size());
  Assert.assertEquals( 1, desc.invalidExternalExports.size());
  Assert.assertEquals( "toto IS titi", desc.invalidExternalExports.iterator().next());
}

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

@Test
public void testParseTargetProperties_ok() throws Exception {
  File dir = new File( this.folder.newFolder(), Constants.PROJECT_DIR_GRAPH + "/c" );
  Utils.createDirectory( dir );
  Utils.writeStringInto( "id: tid1\nhandler: in", new File( dir, "t1.properties" ));
  List<ModelError> errors = TargetValidator.parseTargetProperties( dir.getParentFile().getParentFile(), new Component( "c" ));
  Assert.assertEquals( 1, errors.size());
  Assert.assertEquals( ErrorCode.REC_TARGET_NO_NAME, errors.get( 0 ).getErrorCode());
}

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

@Test
  public void testParseTargetProperties_noProperties() throws Exception {

    File dir = new File( this.folder.newFolder(), Constants.PROJECT_DIR_GRAPH + "/c" );
    Utils.createDirectory( dir );

    Utils.writeStringInto( "id: tid1\nhandler: in", new File( dir, "t1.not-properties" ));

    List<ModelError> errors = TargetValidator.parseTargetProperties( dir, new Component( "c" ));
    Assert.assertEquals( 0, errors.size());
  }
}

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

@Test
public void testValidExternalExports() throws Exception {
  File f = this.folder.newFile();
  Utils.writeStringInto( "exports: HAProxy.ip as lb-ip, HAProxy.httpPort as lb-port", f );
  ApplicationTemplateDescriptor desc = ApplicationTemplateDescriptor.load( f );
  Assert.assertEquals( 0, desc.invalidExternalExports.size());
  Assert.assertEquals( 2, desc.externalExports.size());
  Assert.assertEquals( "lb-ip", desc.externalExports.get( "HAProxy.ip" ));
  Assert.assertEquals( "lb-port", desc.externalExports.get( "HAProxy.httpPort" ));
}

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

@Test
public void testReadPropertiesFileQuietly() throws Exception {
  File f = this.folder.newFile();
  Utils.writeStringInto( "prop: op", f );
  Logger logger = Logger.getLogger( getClass().getName());
  // Normal
  Properties props = Utils.readPropertiesFileQuietly( f, logger );
  Assert.assertEquals( 1, props.size());
  Assert.assertEquals( "op", props.get( "prop" ));
  // Inexisting file
  props = Utils.readPropertiesFileQuietly( new File( "inexisting" ), logger );
  Assert.assertEquals( 0, props.size());
  // Null file
  props = Utils.readPropertiesFileQuietly( null, logger );
  Assert.assertEquals( 0, props.size());
}

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

@Test
public void testScriptValidation_success() throws Exception {
  File appDir = this.folder.newFolder();
  Component comp = new Component( "toto" ).installerName( "script" );
  File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp );
  Assert.assertTrue( new File( directory, RecipesValidator.SCRIPTS_DIR_NAME ).mkdirs());
  Utils.writeStringInto( "\ntest", new File( directory, RecipesValidator.SCRIPTS_DIR_NAME + "/test.sh" ));
  Assert.assertEquals( 0, RecipesValidator.validateComponentRecipes( appDir, comp ).size());
}

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

@Test
public void testScriptValidation_noScriptsDirectory() throws Exception {
  File appDir = this.folder.newFolder();
  Component comp = new Component( "toto" ).installerName( "script" );
  File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp );
  Assert.assertTrue( directory.mkdirs());
  Utils.writeStringInto( "", new File( directory, "test.sh" ));
  List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp );
  Assert.assertEquals( 1, errors.size());
  Assert.assertEquals( ErrorCode.REC_SCRIPT_NO_SCRIPTS_DIR, errors.get( 0 ).getErrorCode());
}

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

@Test
public void testWriteStringInto() throws Exception {
  File f = this.folder.newFile();
  String content = "whatever\n\thop   ";
  Utils.writeStringInto( content, f );
  Assert.assertEquals( content, Utils.readFileContent( f ));
}

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

@Test
public void testValidate_ok_fromFile() throws Exception {
  File f = this.folder.newFile();
  Utils.writeStringInto( "handler: in-memory\nid: tid\nname: some name", f );
  TargetValidator tv = new TargetValidator( f );
  tv.validate();
  Assert.assertEquals( 0, tv.getErrors().size());
}

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

@Test
  public void testValidate_noContextFile_noRecursiveCommand_2() throws Exception {

    // The commands file to execute contains the exact same instruction
    Utils.writeStringInto( "  eXecuTe  " + INVOKED_NAME + "\n# " + INVOKER_NAME + ".commands  ", this.context.getCommandFile());

    // No context file
    this.context = new Context( this.context.getApp(), null );
    Assert.assertTrue( this.cmdToExecute.createNewFile());

    // Commands may not always be loaded from a file.
    String line = "execute " + INVOKER_NAME;
    ExecuteCommandInstruction instr = new ExecuteCommandInstruction( this.context, line, 1 );
    List<ParsingError> errors = instr.validate();

    Assert.assertEquals( 0, errors.size());
  }
}

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

@Test
public void testValidate_noContextFile_withRecursiveCommand() throws Exception {
  // The commands file to execute contains the exact same instruction
  Utils.writeStringInto( "  eXecuTe   " + INVOKER_NAME + ".commands  ", this.context.getCommandFile());
  // No context file
  this.context = new Context( this.context.getApp(), null );
  // Commands may not always be loaded from a file.
  String line = "execute " + INVOKER_NAME;
  ExecuteCommandInstruction instr = new ExecuteCommandInstruction( this.context, line, 1 );
  List<ParsingError> errors = instr.validate();
  Assert.assertEquals( 1, errors.size());
  Assert.assertEquals( ErrorCode.CMD_NASTY_LOOPING_COMMAND, errors.get( 0 ).getErrorCode());
}

相关文章