本文整理了Java中com.thoughtworks.xstream.XStream.<init>()
方法的一些代码示例,展示了XStream.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XStream.<init>()
方法的具体详情如下:
包路径:com.thoughtworks.xstream.XStream
类名称:XStream
方法名:<init>
[英]Constructs a default XStream.
The instance will use the XppDriver as default and tries to determine the best match for the ReflectionProvider on its own.
[中]构造一个默认的XStream。
该实例将使用XppDriver作为默认值,并尝试自行确定ReflectionProvider的最佳匹配。
代码示例来源:origin: jenkinsci/jenkins
/**
* Returns a list of any plugins that are persisted in the installing list
*/
@SuppressWarnings("unchecked")
public static synchronized @CheckForNull Map<String,String> getPersistedInstallStatus() {
File installingPluginsFile = getInstallingPluginsFile();
if(installingPluginsFile == null || !installingPluginsFile.exists()) {
return null;
}
return (Map<String,String>)new XStream().fromXML(installingPluginsFile);
}
代码示例来源:origin: stackoverflow.com
public static boolean toXML(Object object, File file) {
XStream xStream = new XStream();
OutputStream outputStream = null;
Writer writer = null;
try {
outputStream = new FileOutputStream(file);
writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8"));
xStream.toXML(object, writer);
}
catch (Exception exp) {
log.error(null, exp);
return false;
}
finally {
close(writer);
close(outputStream);
}
return true;
}
代码示例来源:origin: stackoverflow.com
XStream xstream = new XStream();
xstream.alias("person", Person.class);
xstream.alias("persons", PersonList.class);
xstream.addImplicitCollection(PersonList.class, "list");
PersonList list = new PersonList();
list.add(new Person("ABC",12,"address"));
list.add(new Person("XYZ",20,"address2"));
String xml = xstream.toXML(list);
代码示例来源:origin: kiegroup/optaplanner
public static <T> T serializeAndDeserializeWithXStream(T input) {
XStream xStream = new XStream();
xStream.setMode(XStream.ID_REFERENCES);
if (input != null) {
xStream.processAnnotations(input.getClass());
}
XStream.setupDefaultSecurity(xStream);
xStream.addPermission(new AnyTypePermission());
String xmlString = xStream.toXML(input);
return (T) xStream.fromXML(xmlString);
}
代码示例来源:origin: stackoverflow.com
XStream xStream = new XStream();
xStream.alias("Strings", String[].class);
xStream.alias("String", String.class);
String[] result = (String[])xStream.fromXML(file);
代码示例来源:origin: javamelody/javamelody
private static XStream createXStream(boolean json) {
final XStream xstream;
if (json) {
// format json
xstream = new XStream(new JsonHierarchicalStreamDriver());
xstream.setMode(XStream.NO_REFERENCES);
} else {
// sinon format xml, utilise la dépendance XPP3 par défaut
xstream = new XStream();
}
for (final Map.Entry<String, Class<?>> entry : XStreamAlias.getMap().entrySet()) {
xstream.alias(entry.getKey(), entry.getValue());
}
final MapConverter mapConverter = new MapConverter(xstream.getMapper()) {
/** {@inheritDoc} */
@SuppressWarnings("rawtypes")
@Override
public boolean canConvert(Class type) {
return true; // Counter.requests est bien une map
}
};
xstream.registerLocalConverter(Counter.class, "requests", mapConverter);
xstream.registerLocalConverter(Counter.class, "rootCurrentContextsByThreadId",
mapConverter);
return xstream;
}
}
代码示例来源:origin: stackoverflow.com
map.put("island","faranga");
XStream magicApi = new XStream();
magicApi.registerConverter(new MapEntryConverter());
magicApi.alias("root", Map.class);
String xml = magicApi.toXML(map);
System.out.println("Result of tweaked XStream toXml()");
System.out.println(xml);
Map<String, String> extractedMap = (Map<String, String>) magicApi.fromXML(xml);
assert extractedMap.get("name").equals("chris");
assert extractedMap.get("island").equals("faranga");
代码示例来源:origin: apache/cloudstack
InputStream is = method.getResponseBodyAsStream();
XStream xstream = new XStream(new DomDriver());
xstream.alias("account", RegionAccount.class);
xstream.alias("user", RegionUser.class);
xstream.aliasField("id", RegionAccount.class, "uuid");
xstream.aliasField("name", RegionAccount.class, "accountName");
代码示例来源:origin: org.aperteworkflow/integration
private Collection<ProcessRoleConfig> getRoles(InputStream input) {
if (input == null) {
return null;
}
XStream xstream = new XStream();
xstream.aliasPackage("config", ProcessRoleConfig.class.getPackage().getName());
xstream.useAttributeFor(String.class);
xstream.useAttributeFor(Boolean.class);
xstream.useAttributeFor(Integer.class);
return (Collection<ProcessRoleConfig>) xstream.fromXML(input);
}
代码示例来源:origin: kiegroup/optaplanner
protected <S extends Score, W extends TestScoreWrapper<S>> void assertSerializeAndDeserialize(S expectedScore, W input) {
XStream xStream = new XStream();
xStream.setMode(XStream.ID_REFERENCES);
xStream.processAnnotations(input.getClass());
XStream.setupDefaultSecurity(xStream);
xStream.allowTypesByRegExp(new String[]{"org\\.optaplanner\\.\\w+\\.config\\..*",
"org\\.optaplanner\\.persistence\\.xstream\\..*\\$Test\\w+ScoreWrapper"});
String xmlString = xStream.toXML(input);
W output = (W) xStream.fromXML(xmlString);
assertEquals(expectedScore, output.getScore());
String regex;
if (expectedScore != null) {
regex = "<([\\w\\-\\.]+)( id=\"\\d+\")?>" // Start of element
+ "\\s*<score( id=\"\\d+\")?>"
+ expectedScore.toString().replaceAll("\\[", "\\\\[").replaceAll("\\]", "\\\\]") // Score
+ "</score>"
+ "\\s*</\\1>"; // End of element
} else {
regex = "<([\\w\\-\\.]+)( id=\"\\d+\")?/>"; // Start and end of element
}
if (!xmlString.matches(regex)) {
fail("Regular expression match failed.\nExpected regular expression: " + regex + "\nActual string: " + xmlString);
}
}
代码示例来源:origin: stackoverflow.com
List <String> list = new ArrayList <String>();
list.add("a");
list.add("b");
XStream xStream = new XStream();
xStream.alias("Strings", List.class);
xStream.alias("String", String.class);
String result = xStream.toXML(list);
代码示例来源:origin: stackoverflow.com
XStream xStream = new XStream();
xStream.alias("Strings", ArrayList.class);
xStream.alias("String", String.class);
xStream.addImplicitArray(ArrayList.class, "elementData");
List <String> result = (List <String>)xStream.fromXML(file);
代码示例来源:origin: apache/ignite
/**
* Reads configuration from given file and delete the file after.
*
* @param fileName File name.
* @return Readed configuration.
* @throws IOException If failed.
* @see #storeToFile(IgniteConfiguration, boolean)
* @throws IgniteCheckedException On error.
*/
private static IgniteConfiguration readCfgFromFileAndDeleteFile(String fileName)
throws IOException, IgniteCheckedException {
try(BufferedReader cfgReader = new BufferedReader(new FileReader(fileName))) {
IgniteConfiguration cfg = (IgniteConfiguration)new XStream().fromXML(cfgReader);
if (cfg.getMarshaller() == null) {
Marshaller marsh = IgniteTestResources.getMarshaller();
cfg.setMarshaller(marsh);
}
X.println("Configured marshaller class: " + cfg.getMarshaller().getClass().getName());
if (cfg.getDiscoverySpi() == null) {
TcpDiscoverySpi disco = new TcpDiscoverySpi();
disco.setIpFinder(GridCacheAbstractFullApiSelfTest.LOCAL_IP_FINDER);
cfg.setDiscoverySpi(disco);
}
X.println("Configured discovery: " + cfg.getDiscoverySpi().getClass().getName());
return cfg;
}
finally {
new File(fileName).delete();
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Persists a list of installing plugins; this is used in the case Jenkins fails mid-installation and needs to be restarted
* @param installingPlugins
*/
public static synchronized void persistInstallStatus(List<UpdateCenterJob> installingPlugins) {
File installingPluginsFile = getInstallingPluginsFile();
if(installingPlugins == null || installingPlugins.isEmpty()) {
installingPluginsFile.delete();
return;
}
LOGGER.fine("Writing install state to: " + installingPluginsFile.getAbsolutePath());
Map<String,String> statuses = new HashMap<String,String>();
for(UpdateCenterJob j : installingPlugins) {
if(j instanceof InstallationJob && j.getCorrelationId() != null) { // only include install jobs with a correlation id (directly selected)
InstallationJob ij = (InstallationJob)j;
InstallationStatus status = ij.status;
String statusText = status.getType();
if(status instanceof Installing) { // flag currently installing plugins as pending
statusText = "Pending";
}
statuses.put(ij.plugin.name, statusText);
}
}
try {
String installingPluginXml = new XStream().toXML(statuses);
FileUtils.write(installingPluginsFile, installingPluginXml);
} catch (IOException e) {
LOGGER.log(SEVERE, "Failed to save " + installingPluginsFile.getAbsolutePath(), e);
}
}
代码示例来源:origin: Impetus/Kundera
/**
* get XStream Object.
*
* @return XStream object.
*/
private XStream getXStreamObject()
{
XStream stream = new XStream();
stream.alias("indexerProperties", IndexerProperties.class);
stream.alias("node", IndexerProperties.Node.class);
return stream;
}
代码示例来源:origin: stackoverflow.com
XStream xstream = new XStream();
xstream.autodetectAnnotations(true);
xstream.alias("settings", HashMap.class);
xstream.registerConverter(new MapEntryConverter());
...
// Parse:
YourObject yourObject = (YourObject) xstream.fromXML(is);
// Store:
xstream.toXML(yourObject);
...
代码示例来源:origin: apache/cloudstack
if (client.executeMethod(method) == 200) {
InputStream is = method.getResponseBodyAsStream();
XStream xstream = new XStream(new DomDriver());
xstream.alias("useraccount", UserAccountVO.class);
xstream.aliasField("id", UserAccountVO.class, "uuid");
try(ObjectInputStream in = xstream.createObjectInputStream(is);) {
代码示例来源:origin: stackoverflow.com
XStream xstream = new XStream();
//converting object to XML
String xml = xstream.toXML(myObject);
//converting xml to object
MyClass myObject = (MyClass)xstream.fromXML(xml);
代码示例来源:origin: org.geoserver/restconfig
@Override
protected void write(Object data, OutputStream output)
throws IOException {
XStream xstream = new XStream();
xstream.alias( "featureTypeName", String.class);
xstream.toXML( data, output );
}
};
代码示例来源:origin: stackoverflow.com
XStream xstream = new XStream();
xstream.alias("comments", Comments.class);
xstream.alias("comment", Comment.class);
xstream.addImplicitCollection(Comments.class, "comments");
Comments comments = (Comments)xstream.fromXML(xml);
内容来源于网络,如有侵权,请联系作者删除!