當前位置: 首頁>>代碼示例>>Java>>正文


Java Persister.write方法代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:GilbertoMattos,項目名稱:nfce,代碼行數:11,代碼來源:NFBase.java

示例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);
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:17,代碼來源:DefaultEmptyTest.java

示例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);
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:27,代碼來源:VisitorStrategyTest.java

示例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());
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:18,代碼來源:SimpleExecutor.java

示例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");
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:27,代碼來源:RegistryMatcherTest.java

示例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());
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:25,代碼來源:CombinedStrategyTest.java

示例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());      
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:27,代碼來源:CombinedStrategyTest.java

示例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);
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:11,代碼來源:Example6.java

示例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);
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:10,代碼來源:Example11.java

示例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);
   
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:11,代碼來源:SerializeRandomListOfObjectsTest.java

示例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);
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:10,代碼來源:Example10.java

示例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);
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:13,代碼來源:CommentTest.java

示例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);
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:11,代碼來源:Example8.java

示例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);
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:11,代碼來源:NamespaceTest.java

示例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);      
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:34,代碼來源:DateTransformTest.java


注:本文中的org.simpleframework.xml.core.Persister.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。