本文整理了Java中net.roboconf.core.utils.Utils.copyStream()
方法的一些代码示例,展示了Utils.copyStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.copyStream()
方法的具体详情如下:
包路径:net.roboconf.core.utils.Utils
类名称:Utils
方法名:copyStream
[英]Copies the content from inputFile into outputFile.
[中]将内容从inputFile复制到outputFile。
代码示例来源:origin: roboconf/roboconf-platform
/**
* Writes a string into a file.
*
* @param s the string to write (not null)
* @param outputFile the file to write into
* @throws IOException if something went wrong
*/
public static void writeStringInto( String s, File outputFile ) throws IOException {
InputStream in = new ByteArrayInputStream( s.getBytes( StandardCharsets.UTF_8 ));
copyStream( in, outputFile );
}
代码示例来源:origin: roboconf/roboconf-platform
@Override
protected File writeFileContent(String fileContent) throws IOException {
// Load the template
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = getClass().getResourceAsStream( "/fop.tpl" );
Utils.copyStreamSafely( in, out );
//Copy the header in outputDirectory
InputStream h = getClass().getResourceAsStream( "/roboconf.jpg" );
File imgFile = new File( this.outputDirectory, "header.jpg" );
Utils.copyStream( h, imgFile );
// Create the target directory
File targetFile = new File( this.outputDirectory, "index.fo" );
Utils.createDirectory( targetFile.getParentFile());
// Write the main file
String toWrite = out.toString( "UTF-8" )
.replace( TITLE_MARKUP, this.applicationTemplate.getName())
.replace( CONTENT_MARKUP, fileContent )
.replace( "header.jpg", this.outputDirectory.getAbsolutePath() + "/header.jpg" )
.replace( "png/", this.outputDirectory.getAbsolutePath() + "/png/" )
.replaceAll( "\n{3,}", "\n\n" );
Utils.writeStringInto( toWrite, targetFile );
return targetFile;
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Copies the content from inputFile into outputFile.
*
* @param inputFile an input file (must be a file and exist)
* @param outputFile will be created if it does not exist
* @throws IOException if something went wrong
*/
public static void copyStream( File inputFile, File outputFile ) throws IOException {
InputStream is = new FileInputStream( inputFile );
try {
copyStream( is, outputFile );
} finally {
is.close();
}
}
代码示例来源:origin: net.roboconf/roboconf-iaas-azure
private byte[] convertFileToByte(String xmlFilePath) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
Utils.copyStream ( new File(xmlFilePath), os );
} catch (IOException e) {
this.logger.severe( e.getMessage());
}
return os.toByteArray();
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Reads a text file content and returns it as a string.
* <p>
* The file is tried to be read with UTF-8 encoding.
* If it fails, the default system encoding is used.
* </p>
*
* @param file the file whose content must be loaded
* @return the file content
* @throws IOException if the file content could not be read
*/
public static String readFileContent( File file ) throws IOException {
String result = null;
ByteArrayOutputStream os = new ByteArrayOutputStream();
Utils.copyStream( file, os );
result = os.toString( "UTF-8" );
return result;
}
代码示例来源:origin: net.roboconf/roboconf-iaas-azure
private String getStringFromInputStream( InputStream in ) {
String result = "";
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
Utils.copyStream( in, os );
result = os.toString( "UTF-8" );
} catch( IOException e ) {
this.logger.severe( e.getMessage());
this.logger.finest( Utils.writeException( e ));
}
return result;
}
代码示例来源:origin: net.roboconf/roboconf-doc-generator
private void writeCssFile() throws IOException {
InputStream in = null;
String location = this.options.get( DocConstants.OPTION_HTML_CSS_FILE );
try {
if( ! Utils.isEmptyOrWhitespaces( location ))
in = new FileInputStream( new File( location ));
else
in = getClass().getResourceAsStream( "/style.css" );
File cssFile = new File( this.outputDirectory, "style.css" );
Utils.copyStream( in, cssFile );
} finally {
Utils.closeQuietly( in );
}
}
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Saves the model into another file.
* @param targetFile the target file (may not exist)
* @param relationsFile the relations file
* @param writeComments true to write comments
* @param lineSeparator the line separator (if null, the OS' one is used)
* @throws IOException if the file could not be saved
*/
public static void saveRelationsFileInto(
File targetFile,
FileDefinition relationsFile,
boolean writeComments,
String lineSeparator )
throws IOException {
String s = writeConfigurationFile( relationsFile, writeComments, lineSeparator );
Utils.copyStream( new ByteArrayInputStream( s.getBytes( StandardCharsets.UTF_8 )), targetFile );
}
}
代码示例来源:origin: roboconf/roboconf-platform
private void writeCssFile() throws IOException {
InputStream in = null;
String location = this.options.get( DocConstants.OPTION_HTML_CSS_FILE );
try {
if( ! Utils.isEmptyOrWhitespaces( location ))
in = new FileInputStream( new File( location ));
else
in = getClass().getResourceAsStream( "/style.css" );
File cssFile = new File( this.outputDirectory, "style.css" );
Utils.copyStream( in, cssFile );
} finally {
Utils.closeQuietly( in );
}
}
}
代码示例来源:origin: net.roboconf/roboconf-agent
/**
* Copies the resources of an instance on the disk.
* @param instance an instance
* @param fileNameToFileContent the files to write down (key = relative file location, value = file's content)
* @throws IOException if the copy encountered a problem
*/
public static void copyInstanceResources( Instance instance, Map<String,byte[]> fileNameToFileContent )
throws IOException {
File dir = InstanceHelpers.findInstanceDirectoryOnAgent( instance );
Utils.createDirectory( dir );
if( fileNameToFileContent != null ) {
for( Map.Entry<String,byte[]> entry : fileNameToFileContent.entrySet()) {
File f = new File( dir, entry.getKey());
Utils.createDirectory( f.getParentFile());
ByteArrayInputStream in = new ByteArrayInputStream( entry.getValue());
Utils.copyStream( in, f );
}
}
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testInvalidApplicationDescriptor() throws Exception {
File appDirectory = this.folder.newFolder();
File descDirectory = new File( appDirectory, Constants.PROJECT_DIR_DESC );
if( ! descDirectory.mkdir())
throw new IOException();
File descFile = new File( descDirectory, Constants.PROJECT_FILE_DESCRIPTOR );
if( ! descFile.createNewFile())
throw new IOException();
String content = "fail.read = true";
Utils.copyStream( new ByteArrayInputStream( content.getBytes( "UTF-8" )), descFile );
ApplicationLoadResult lr = RuntimeModelIo.loadApplication( appDirectory );
Assert.assertTrue( lr.getLoadErrors().size() > 1 );
Assert.assertEquals( ErrorCode.PROJ_READ_DESC_FILE, lr.getLoadErrors().iterator().next().getErrorCode());
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testPuppetValidation_validUpdatePp() throws Exception {
File appDir = this.folder.newFolder();
Component comp = new Component( "toto" ).installerName( "puppet" );
File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp );
Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs());
File targetFile = new File( directory, "roboconf_toto/manifests/update.pp" );
File inputFile = TestUtils.findTestFile( "/recipes/update.pp" );
Utils.copyStream( inputFile, targetFile );
List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp );
Assert.assertEquals( 0, errors.size());
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testPuppetValidation_invalidUpdatePp_validInitPp() throws Exception {
File appDir = this.folder.newFolder();
Component comp = new Component( "toto" ).installerName( "puppet" );
File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp );
Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs());
File targetFile = new File( directory, "roboconf_toto/manifests/init.pp" );
File inputFile = TestUtils.findTestFile( "/recipes/invalid-update.pp" );
Utils.copyStream( inputFile, targetFile );
targetFile = new File( directory, "roboconf_toto/manifests/update.pp" );
Utils.copyStream( inputFile, targetFile );
// The init.pp is not considered as being called during updates.
// So, no error about imports.
List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp );
Assert.assertEquals( 1, errors.size());
Assert.assertEquals( ErrorCode.REC_PUPPET_MISSING_PARAM_IMPORT_DIFF, errors.get( 0 ).getErrorCode());
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testPuppetValidation_onlyStartPp() throws Exception {
File appDir = this.folder.newFolder();
Component comp = new Component( "toto" ).installerName( "puppet" );
File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp );
Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs());
File targetFile = new File( directory, "roboconf_toto/manifests/start.pp" );
File inputFile = TestUtils.findTestFile( "/recipes/invalid-update.pp" );
Utils.copyStream( inputFile, targetFile );
List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp );
Assert.assertEquals( 0, errors.size());
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testAllCommands() throws Exception {
this.app.setDirectory( this.folder.newFolder());
File cmdDir = new File( this.app.getDirectory(), Constants.PROJECT_DIR_COMMANDS );
Assert.assertTrue( cmdDir.mkdirs());
File f = TestUtils.findTestFile( "/commands/single-line-commands.txt" );
Utils.copyStream( f, new File( cmdDir, "single-line-commands" + Constants.FILE_EXT_COMMANDS ));
f = TestUtils.findTestFile( "/commands/all-commands.txt" );
CommandsParser parser = new CommandsParser( this.app, f );
List<ParsingError> errors = parser.getParsingErrors();
Assert.assertEquals( 0, errors.size());
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testPuppetValidation_invalidUpdatePp() throws Exception {
File appDir = this.folder.newFolder();
Component comp = new Component( "toto" ).installerName( "puppet" );
File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp );
Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs());
File targetFile = new File( directory, "roboconf_toto/manifests/update.pp" );
File inputFile = TestUtils.findTestFile( "/recipes/invalid-update.pp" );
Utils.copyStream( inputFile, targetFile );
List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp );
Assert.assertEquals( 1, errors.size());
Assert.assertEquals( ErrorCode.REC_PUPPET_MISSING_PARAM_IMPORT_DIFF, errors.get( 0 ).getErrorCode());
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testPuppetValidation_invalidInitPp() throws Exception {
File appDir = this.folder.newFolder();
Component comp = new Component( "toto" ).installerName( "puppet" );
File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp );
Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs());
File targetFile = new File( directory, "roboconf_toto/manifests/init.pp" );
File inputFile = TestUtils.findTestFile( "/recipes/invalid-update.pp" );
Utils.copyStream( inputFile, targetFile );
List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp );
Assert.assertEquals( 1, errors.size());
Assert.assertEquals( ErrorCode.REC_PUPPET_MISSING_PARAM_IMPORT_DIFF, errors.get( 0 ).getErrorCode());
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testPuppetValidation_missingRunningState() throws Exception {
File appDir = this.folder.newFolder();
Component comp = new Component( "toto" ).installerName( "puppet" );
File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp );
Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs());
File targetFile = new File( directory, "roboconf_toto/manifests/start.pp" );
File inputFile = TestUtils.findTestFile( "/recipes/missing-running-state.pp" );
Utils.copyStream( inputFile, targetFile );
List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp );
Assert.assertEquals( 1, errors.size());
Assert.assertEquals( ErrorCode.REC_PUPPET_MISSING_PARAM_RUNNING_STATE, errors.get( 0 ).getErrorCode());
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testPuppetValidation_withMatchingImport() throws Exception {
File appDir = this.folder.newFolder();
Component comp = new Component( "toto" ).installerName( "puppet" );
comp.addImportedVariable( new ImportedVariable( "WithInit.value", true, false ));
File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp );
Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs());
File targetFile = new File( directory, "roboconf_toto/manifests/start.pp" );
File inputFile = TestUtils.findTestFile( "/recipes/update.pp" );
Utils.copyStream( inputFile, targetFile );
// We only parse what we know...
List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp );
Assert.assertEquals( 0, errors.size());
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testPuppetValidation_invalidSyntax() throws Exception {
Assume.assumeTrue(puppetIsInstalled());
File appDir = this.folder.newFolder();
Component comp = new Component( "toto" ).installerName( "puppet" );
File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp );
Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs());
File targetFile = new File( directory, "roboconf_toto/manifests/start.pp" );
File inputFile = TestUtils.findTestFile( "/recipes/invalid-syntax.pp" );
Utils.copyStream( inputFile, targetFile );
// We only parse what we know...
List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp );
Assert.assertEquals( 1, errors.size());
Assert.assertEquals( ErrorCode.REC_PUPPET_SYNTAX_ERROR, errors.get( 0 ).getErrorCode());
}
}
内容来源于网络,如有侵权,请联系作者删除!