本文整理汇总了Java中org.simpleframework.xml.core.Persister.write方法的典型用法代码示例。如果您正苦于以下问题:Java Persister.write方法的具体用法?Java Persister.write怎么用?Java Persister.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.simpleframework.xml.core.Persister
的用法示例。
在下文中一共展示了Persister.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toString
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
@Override
public String toString() {
final Persister persister = new NFPersister();
try (StringWriter writer = new StringWriter()) {
persister.write(this, writer);
return writer.toString();
} catch (final Exception e) {
throw new IllegalStateException(e.getMessage());
}
}
示例2: testDefaults
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testDefaults() throws Exception {
Persister persister = new Persister();
DefaultExample example = persister.read(DefaultExample.class, SOURCE);
assertEquals(example.name, "test");
assertEquals(example.text, "some text");
assertNotNull(example.stringList);
assertNotNull(example.stringMap);
assertNotNull(example.stringArray);
persister.write(example, System.out);
validate(persister, example);
persister.write(new DefaultExample("name", "example text"), System.out);
}
示例3: testStrategy
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testStrategy() throws Exception {
Visitor visitor = new ClassToNamespaceVisitor();
Strategy strategy = new VisitorStrategy(visitor);
Persister persister = new Persister(strategy);
VisitorExample item = new VisitorExample();
StringWriter writer = new StringWriter();
item.put("1", "ONE");
item.put("2", "TWO");
item.add("A");
item.add("B");
persister.write(item, writer);
String text = writer.toString();
System.out.println(text);
VisitorExample recover = persister.read(VisitorExample.class, text);
assertTrue(recover.map.containsKey("1"));
assertTrue(recover.map.containsKey("2"));
assertTrue(recover.items.contains("A"));
assertTrue(recover.items.contains("B"));
validate(recover, persister);
}
示例4: write
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public Duration write(TestRun test) throws Exception {
long start = System.currentTimeMillis();
Persister persister = new Persister();
Class schemaClass = test.getSchemaClass();
Object result = persister.read(schemaClass, test.getSourceStream());
// Perform once to build up schema cache
if(test.isDebug()) {
persister.write(result, System.out);
}
long startWrite = System.currentTimeMillis();
for(int i = 0; i < test.getIterations(); i++) {
persister.write(result, test.getResultWriter());
}
return new Duration(start, startWrite, test.getIterations());
}
示例5: testMatcher
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testMatcher() throws Exception {
RegistryMatcher matcher = new RegistryMatcher();
Transform<C> transform = new CTransform();
matcher.bind(A.class, ATransform.class);
matcher.bind(B.class, BTransform.class);
matcher.bind(C.class, transform);
Transform<A> a = matcher.match(A.class);
Transform<B> b = matcher.match(B.class);
Transform<C> c = matcher.match(C.class);
A ia = a.read("A");
B ib = b.read("B");
C ic = c.read("C");
assertEquals(ia.getValue(), "A");
assertEquals(ib.getValue(), "B");
assertEquals(ic.getValue(), "C");
Persister persister = new Persister(matcher);
Example example = new Example(ia, ib, ic);
StringWriter writer = new StringWriter();
persister.write(example, writer);
String text = writer.toString();
assertElementExists(text, "/example");
assertElementExists(text, "/example/a");
assertElementHasValue(text, "/example/a", "A");
assertElementHasAttribute(text, "/example", "b", "B");
assertElementHasAttribute(text, "/example", "c", "C");
}
示例6: testCombinedStrategy
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testCombinedStrategy() throws Exception {
Registry registry = new Registry();
AnnotationStrategy annotationStrategy = new AnnotationStrategy();
RegistryStrategy registryStrategy = new RegistryStrategy(registry, annotationStrategy);
Persister persister = new Persister(registryStrategy);
CombinationExample example = new CombinationExample(1, 2, 3);
StringWriter writer = new StringWriter();
registry.bind(Item.class, RegistryItemConverter.class);
persister.write(example, writer);
String text = writer.toString();
System.out.println(text);
assertElementExists(text, "/combinationExample/item/value");
assertElementHasValue(text, "/combinationExample/item/value", "1");
assertElementHasValue(text, "/combinationExample/item/type", RegistryItemConverter.class.getName());
assertElementExists(text, "/combinationExample/overriddenItem");
assertElementHasAttribute(text, "/combinationExample/overriddenItem", "value", "2");
assertElementHasAttribute(text, "/combinationExample/overriddenItem", "type", AnnotationItemConverter.class.getName());
assertElementExists(text, "/combinationExample/extendedItem");
assertElementHasAttribute(text, "/combinationExample/extendedItem", "value", "3");
assertElementHasAttribute(text, "/combinationExample/extendedItem", "type", ExtendedItemConverter.class.getName());
}
示例7: testCombinationStrategyWithStyle
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testCombinationStrategyWithStyle() throws Exception {
Registry registry = new Registry();
AnnotationStrategy annotationStrategy = new AnnotationStrategy();
RegistryStrategy registryStrategy = new RegistryStrategy(registry, annotationStrategy);
Style style = new HyphenStyle();
Format format = new Format(style);
Persister persister = new Persister(registryStrategy, format);
CombinationExample example = new CombinationExample(1, 2, 3);
StringWriter writer = new StringWriter();
registry.bind(Item.class, RegistryItemConverter.class);
persister.write(example, writer);
String text = writer.toString();
System.out.println(text);
assertElementExists(text, "/combination-example/item/value");
assertElementHasValue(text, "/combination-example/item/value", "1");
assertElementHasValue(text, "/combination-example/item/type", RegistryItemConverter.class.getName());
assertElementExists(text, "/combination-example/overridden-item");
assertElementHasAttribute(text, "/combination-example/overridden-item", "value", "2");
assertElementHasAttribute(text, "/combination-example/overridden-item", "type", AnnotationItemConverter.class.getName());
assertElementExists(text, "/combination-example/extended-item");
assertElementHasAttribute(text, "/combination-example/extended-item", "value", "3");
assertElementHasAttribute(text, "/combination-example/extended-item", "type", ExtendedItemConverter.class.getName());
}
示例8: main
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public static void main(String[] list) throws Exception {
Persister persister = new Persister();
File file = new File("example6/example6.xml");
Example example = persister.read(Example.class, file);
System.out.println(example.a);
System.out.println(example.b);
persister.write(example, System.out);
}
示例9: main
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public static void main(String[] list) throws Exception {
Persister persister = new Persister();
File file = new File("example11/example11.xml");
Example example = persister.read(Example.class, file);
System.out.println(example.value);
persister.write(example, System.out);
}
示例10: testSerializeRandomList
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testSerializeRandomList() throws Exception {
List list = new ArrayList();
list.add("x");
list.add(10);
list.add(new Date());
ListArgument argument = new ListArgument(list);
Persister persister = new Persister();
persister.write(argument, System.out);
}
示例11: main
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public static void main(String[] list) throws Exception {
Persister persister = new Persister();
File file = new File("example10/example10.xml");
Example example = persister.read(Example.class, file);
System.out.println(example.list);
persister.write(example, System.out);
}
示例12: testComment
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testComment() throws Exception {
Visitor visitor = new CommentVisitor();
Strategy strategy = new VisitorStrategy(visitor);
Persister persister = new Persister(strategy);
CommentExample example = new CommentExample();
example.name = "Some Name";
example.value = "A value to use";
example.price = 9.99;
persister.write(example, System.out);
}
示例13: main
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public static void main(String[] list) throws Exception {
Persister persister = new Persister();
File file = new File("example8/example8.xml");
Example example = persister.read(Example.class, file);
System.out.println(example.b);
System.out.println(example.c);
persister.write(example, System.out);
}
示例14: testNamespace
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testNamespace() throws Exception {
Persister persister = new Persister();
Employer employer = new Employer("Spam Soft", "Sesame Street", true, 1000);
Profession job = new Profession("Software Engineer", 10, 12, employer);
Person person = new Person("John Doe", "Person", 30, job);
persister.write(person, System.out);
validate(persister, person);
}
示例15: testCyclicPersistence
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testCyclicPersistence() throws Exception {
long now = System.currentTimeMillis();
Date date = new Date(now);
CycleStrategy strategy = new CycleStrategy();
Persister persister = new Persister(strategy);
DateExample example = new DateExample(date);
StringWriter out = new StringWriter();
assertEquals(example.attribute, date);
assertEquals(example.element, date);
assertEquals(example.array[0], date);
assertEquals(example.list.get(0), date);
assertEquals(example.list.get(1), date);
persister.write(example, out);
String text = out.toString();
assertElementHasAttribute(text, "/dateExample", "id", "0");
assertElementHasAttribute(text, "/dateExample/array", "id", "1");
assertElementHasAttribute(text, "/dateExample/array/date", "id", "2");
assertElementHasAttribute(text, "/dateExample/element", "reference", "2");
assertElementHasAttribute(text, "/dateExample/list", "id", "3");
example = persister.read(DateExample.class, text);
assertEquals(example.attribute, date);
assertEquals(example.element, date);
assertEquals(example.array[0], date);
assertEquals(example.list.get(0), date);
assertEquals(example.list.get(1), date);
validate(example, persister);
}