本文整理了Java中net.roboconf.core.utils.Utils
类的一些代码示例,展示了Utils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils
类的具体详情如下:
包路径:net.roboconf.core.utils.Utils
类名称:Utils
[英]Various utilities.
[中]各种公用设施。
代码示例来源:origin: net.roboconf/roboconf-messaging-api
private String getAgentId() {
return Utils.isEmptyOrWhitespaces( this.scopedInstancePath ) ? "?" : this.scopedInstancePath;
}
}
代码示例来源:origin: net.roboconf/roboconf-dm
/**
* Constructor.
*/
public ConfigurationMngrImpl() {
String karafData = System.getProperty( Constants.KARAF_DATA );
if( Utils.isEmptyOrWhitespaces( karafData ))
this.workingDirectory = new File( System.getProperty( "java.io.tmpdir" ), "roboconf-dm" );
else
this.workingDirectory = new File( karafData, "roboconf" );
try {
Utils.createDirectory( this.workingDirectory );
} catch( IOException e ) {
this.logger.severe( "The DM's configuration directory could not be found and/or created." );
Utils.logException( this.logger, e );
}
}
代码示例来源: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: net.roboconf/roboconf-dm
private void writeProperties( Properties props, File file ) throws IOException {
if( props.isEmpty())
Utils.deleteFilesRecursivelyAndQuietly( file );
else
Utils.writePropertiesFile( props, file );
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Constructor.
* @param propertiesFile
*/
public TargetValidator( File propertiesFile ) {
try {
this.props = Utils.readPropertiesFile( propertiesFile );
this.fileName = propertiesFile.getName();
} catch( Exception e ) {
this.failed = true;
Utils.logException( this.logger, e );
}
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Deletes files recursively and remains quiet even if an exception is thrown.
* @param files the files to delete
*/
public static void deleteFilesRecursivelyAndQuietly( File... files ) {
try {
deleteFilesRecursively( files );
} catch( IOException e ) {
Logger logger = Logger.getLogger( Utils.class.getName());
logException( logger, e );
}
}
代码示例来源:origin: net.roboconf/roboconf-doc-generator
@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
for( String s : directoriesToCreate ) {
File dir = new File( rootDir, s );
Utils.createDirectory( dir );
if( Utils.isEmptyOrWhitespaces( creationBean.getCustomPomLocation()))
in = ProjectUtils.class.getResourceAsStream( "/pom-skeleton.xml" );
else
Utils.copyStreamSafely( in, out );
String tpl = out.toString( "UTF-8" )
.replace( TPL_NAME, creationBean.getProjectName())
Utils.copyStream( new ByteArrayInputStream( tpl.getBytes( StandardCharsets.UTF_8 )), pomFile );
Utils.copyStreamSafely( in, out );
tpl = out.toString( "UTF-8" )
.replace( TPL_NAME, creationBean.getProjectName())
代码示例来源:origin: roboconf/roboconf-platform
/**
* Logs an exception with the given logger and the FINEST level.
* @param logger the logger
* @param t an exception or a throwable
*/
public static void logException( Logger logger, Throwable t ) {
logException( logger, Level.FINEST, t );
}
代码示例来源:origin: net.roboconf/roboconf-agent
result = AgentProperties.readIaasProperties(Utils.readPropertiesFile(propertiesFile));
ByteArrayOutputStream os = new ByteArrayOutputStream();
Utils.copyStreamSafely( in, os );
String ip = os.toString( "UTF-8" );
if(! AgentUtils.isValidIP( ip )) {
Utils.closeQuietly( in );
userDataUrl = new URL( "http://169.254.169.254/latest/meta-data/local-ipv4" );
in = userDataUrl.openStream();
os = new ByteArrayOutputStream();
Utils.copyStreamSafely( in, os );
ip = os.toString( "UTF-8" );
Utils.logException( logger, e );
Utils.closeQuietly( in );
代码示例来源:origin: net.roboconf/roboconf-dm
String s = Utils.format( entry.getValue(), ", " );
format.put( entry.getKey(), s );
Utils.createDirectory( descDir );
Utils.writePropertiesFile( props, appBindingsFile );
Utils.logException( logger, e );
代码示例来源:origin: net.roboconf/roboconf-agent
/**
* Changes the level of the Roboconf logger.
* <p>
* This method assumes the default log configuration for a Roboconf
* distribution has a certain shape. If a user manually changed the log
* configuration (not the level, but the logger name, as an example), then
* this will not work.
* </p>
*/
public static void changeRoboconfLogLevel( String logLevel, String etcDir )
throws IOException {
if( ! Utils.isEmptyOrWhitespaces( etcDir )) {
File f = new File( etcDir, AgentConstants.KARAF_LOG_CONF_FILE );
if( f.exists()) {
Properties props = Utils.readPropertiesFile( f );
props.put( "log4j.logger.net.roboconf", logLevel + ", roboconf" );
Utils.writePropertiesFile( props, f );
}
}
}
代码示例来源:origin: net.roboconf/roboconf-agent
/**
* Reconfigures the messaging.
* @param etcDir the KARAF_ETC directory
* @param msgData the messaging configuration parameters
*/
public void reconfigureMessaging( String etcDir, Map<String,String> msgData )
throws IOException {
String messagingType = msgData.get( MessagingConstants.MESSAGING_TYPE_PROPERTY );
Logger.getLogger( getClass().getName()).fine( "Messaging type for reconfiguration: " + messagingType );
if( ! Utils.isEmptyOrWhitespaces( etcDir )
&& ! Utils.isEmptyOrWhitespaces( messagingType )) {
// Write the messaging configuration
File f = new File( etcDir, "net.roboconf.messaging." + messagingType + ".cfg" );
Logger logger = Logger.getLogger( getClass().getName());
Properties props = Utils.readPropertiesFileQuietly( f, logger );
props.putAll( msgData );
props.remove( MessagingConstants.MESSAGING_TYPE_PROPERTY );
Utils.writePropertiesFile( props, f );
// Set the messaging type
f = new File( etcDir, Constants.KARAF_CFG_FILE_AGENT );
props = Utils.readPropertiesFileQuietly( f, Logger.getLogger( getClass().getName()));
if( messagingType != null ) {
props.put( Constants.MESSAGING_TYPE, messagingType );
Utils.writePropertiesFile( props, f );
}
}
}
代码示例来源:origin: net.roboconf/roboconf-dm-scheduler
private void unscheduleJob( String jobId ) throws IOException {
File f = getJobFile( jobId );
try {
if( f.exists()) {
Properties props = Utils.readPropertiesFileQuietly( f, this.logger );
String appName = props.getProperty( APP_NAME, "" );
if( ! Utils.isEmptyOrWhitespaces( appName ))
this.scheduler.unscheduleJob( TriggerKey.triggerKey( jobId, appName ));
}
} catch( SchedulerException e ) {
// Catch all the exceptions (including the runtime ones)
throw new IOException( e );
} finally {
Utils.deleteFilesRecursively( f );
}
}
代码示例来源: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-agent
/**
* Collect the main log files into a map.
* @param karafData the Karaf's data directory
* @return a non-null map
*/
public static Map<String,byte[]> collectLogs( String karafData ) throws IOException {
Map<String,byte[]> logFiles = new HashMap<>( 2 );
if( ! Utils.isEmptyOrWhitespaces( karafData )) {
String[] names = { "karaf.log", "roboconf.log" };
for( String name : names ) {
File log = new File( karafData, AgentConstants.KARAF_LOGS_DIRECTORY + "/" + name );
if( ! log.exists())
continue;
String content = Utils.readFileContent( log );
logFiles.put( name, content.getBytes( StandardCharsets.UTF_8 ));
}
}
return logFiles;
}
代码示例来源: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
/**
* 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 (can be null)
* @param logger a logger (not null)
* @return the file content or the empty string if an error occurred
*/
public static String readFileContentQuietly( File file, Logger logger ) {
String result = "";
try {
if( file != null && file.exists())
result = readFileContent( file );
} catch( Exception e ) {
logger.severe( "File " + file + " could not be read." );
logException( logger, e );
}
return result;
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Saves an application descriptor.
* @param f the file where the properties will be saved
* @param app an application (not null)
* @throws IOException if the file could not be written
*/
public static void save( File f, Application app ) throws IOException {
Properties properties = new Properties();
if( ! Utils.isEmptyOrWhitespaces( app.getDisplayName()))
properties.setProperty( APPLICATION_NAME, app.getDisplayName());
if( ! Utils.isEmptyOrWhitespaces( app.getDescription()))
properties.setProperty( APPLICATION_DESCRIPTION, app.getDescription());
if( app.getTemplate() != null ) {
if( ! Utils.isEmptyOrWhitespaces( app.getTemplate().getName()))
properties.setProperty( APPLICATION_TPL_NAME, app.getTemplate().getName());
if( ! Utils.isEmptyOrWhitespaces( app.getTemplate().getVersion()))
properties.setProperty( APPLICATION_TPL_VERSION, app.getTemplate().getVersion());
}
Utils.writePropertiesFile( properties, f );
}
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testParsingWithInvalidAutonomicRules() throws Exception {
// Copy the application and update a command file
File dir = TestUtils.findApplicationDirectory( "lamp" );
Assert.assertTrue( dir.isDirectory());
File newDir = this.folder.newFolder();
Utils.copyDirectory( dir, newDir );
File ruleFile = new File( newDir, Constants.PROJECT_DIR_RULES_AUTONOMIC + "/sample.drl" );
Assert.assertTrue( ruleFile.isFile());
File ruleFileCopy = new File( newDir, Constants.PROJECT_DIR_RULES_AUTONOMIC + "/sample.drl-invalid-extension" );
Utils.copyStream( ruleFile, ruleFileCopy );
String s = Utils.readFileContent( ruleFile );
s = s.replace( "scale", "inexisting-command" );
Utils.writeStringInto( s, ruleFile );
// Load it and verify it contains errors
ApplicationLoadResult alr = RuntimeModelIo.loadApplication( newDir );
List<RoboconfError> criticalErrors = new ArrayList<> ();
for( RoboconfError error : alr.getLoadErrors()) {
if( error.getErrorCode().getLevel() == ErrorLevel.SEVERE )
criticalErrors.add( error );
}
Assert.assertEquals( 2, criticalErrors.size());
Assert.assertEquals( ErrorCode.RULE_UNKNOWN_COMMAND, criticalErrors.get( 0 ).getErrorCode());
Assert.assertEquals( ErrorCode.PROJ_INVALID_RULE_EXT, criticalErrors.get( 1 ).getErrorCode());
}
内容来源于网络,如有侵权,请联系作者删除!