本文整理汇总了Java中com.sun.jmx.examples.scandir.config.XmlConfigUtils.write方法的典型用法代码示例。如果您正苦于以下问题:Java XmlConfigUtils.write方法的具体用法?Java XmlConfigUtils.write怎么用?Java XmlConfigUtils.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jmx.examples.scandir.config.XmlConfigUtils
的用法示例。
在下文中一共展示了XmlConfigUtils.write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLoad
import com.sun.jmx.examples.scandir.config.XmlConfigUtils; //导入方法依赖的package包/类
/**
* Test of load method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
*/
public void testLoad() throws Exception {
System.out.println("load");
final File file = File.createTempFile("testconf",".xml");
final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
final ScanManagerConfig bean =
new ScanManagerConfig("testLoad");
final DirectoryScannerConfig dir =
new DirectoryScannerConfig("tmp");
dir.setRootDirectory(file.getParent());
bean.putScan(dir);
XmlConfigUtils.write(bean,new FileOutputStream(file),false);
instance.load();
assertEquals(bean,instance.getConfiguration());
bean.removeScan(dir.getName());
XmlConfigUtils.write(bean,new FileOutputStream(file),false);
assertNotSame(bean,instance.getConfiguration());
instance.load();
assertEquals(bean,instance.getConfiguration());
}
示例2: logToFile
import com.sun.jmx.examples.scandir.config.XmlConfigUtils; //导入方法依赖的package包/类
private void logToFile(ResultRecord record) throws IOException {
final String basename;
final long maxRecords;
synchronized (this) {
if (logFile == null) return;
basename = getLogFileName(false);
maxRecords = fileCapacity;
}
// Get the stream into which we should log.
final OutputStream stream =
checkLogFile(basename,maxRecords,false);
// logging to file now disabled - too bad.
if (stream == null) return;
synchronized (this) {
try {
XmlConfigUtils.write(record,stream,true);
stream.flush();
// don't increment logCount if we were not logging in logStream.
if (stream == logStream) logCount++;
} catch (JAXBException x) {
final IllegalArgumentException iae =
new IllegalArgumentException("bad record",x);
LOG.finest("Failed to log record: "+x);
throw iae;
}
}
}