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


Java Serializer.write方法代碼示例

本文整理匯總了Java中org.simpleframework.xml.Serializer.write方法的典型用法代碼示例。如果您正苦於以下問題:Java Serializer.write方法的具體用法?Java Serializer.write怎麽用?Java Serializer.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.simpleframework.xml.Serializer的用法示例。


在下文中一共展示了Serializer.write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addShowScenarioShortcut

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
public static Intent addShowScenarioShortcut(Context context, Choice choice) {
    Intent addShowScenarioShortcutIntent = new Intent(context, AddShowScenarioShortcutActivity.class);
    addShowScenarioShortcutIntent = IntentCompat.makeRestartActivityTask(addShowScenarioShortcutIntent.getComponent());
    addShowScenarioShortcutIntent.setAction(Intent.ACTION_VIEW);
    addShowScenarioShortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    Serializer serializer = new Persister();
    ByteArrayOutputStream choiceOutputStream = new ByteArrayOutputStream();
    try {
        serializer.write(choice, choiceOutputStream);
    } catch (Exception e) {
        Log.d(TAG, e.toString());
    }
    String choiceXml = choiceOutputStream.toString();
    addShowScenarioShortcutIntent.putExtra(EXTRA_CHOICE_XML, choiceXml);
    return addShowScenarioShortcutIntent;
}
 
開發者ID:nicholasrout,項目名稱:shortstories,代碼行數:17,代碼來源:IntentUtil.java

示例2: onRenameConfiguration

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
@Override
public void onRenameConfiguration(final String newName) {
	final boolean exists = mDatabaseHelper.configurationExists(newName);
	if (exists) {
		Toast.makeText(this, R.string.uart_configuration_name_already_taken, Toast.LENGTH_LONG).show();
		return;
	}

	final String oldName = mConfiguration.getName();
	mConfiguration.setName(newName);

	try {
		final Format format = new Format(new HyphenStyle());
		final Strategy strategy = new VisitorStrategy(new CommentVisitor());
		final Serializer serializer = new Persister(strategy, format);
		final StringWriter writer = new StringWriter();
		serializer.write(mConfiguration, writer);
		final String xml = writer.toString();

		mDatabaseHelper.renameConfiguration(oldName, newName, xml);
		mWearableSynchronizer.onConfigurationAddedOrEdited(mPreferences.getLong(PREFS_CONFIGURATION, 0), mConfiguration);
		refreshConfigurations();
	} catch (final Exception e) {
		Log.e(TAG, "Error while renaming configuration", e);
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:27,代碼來源:UARTActivity.java

示例3: saveConfiguration

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
/**
 * Saves the given configuration in the database.
 */
private void saveConfiguration() {
	final UartConfiguration configuration = mConfiguration;
	try {
		final Format format = new Format(new HyphenStyle());
		final Strategy strategy = new VisitorStrategy(new CommentVisitor());
		final Serializer serializer = new Persister(strategy, format);
		final StringWriter writer = new StringWriter();
		serializer.write(configuration, writer);
		final String xml = writer.toString();

		mDatabaseHelper.updateConfiguration(configuration.getName(), xml);
		mWearableSynchronizer.onConfigurationAddedOrEdited(mPreferences.getLong(PREFS_CONFIGURATION, 0), configuration);
	} catch (final Exception e) {
		Log.e(TAG, "Error while creating a new configuration", e);
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:20,代碼來源:UARTActivity.java

示例4: parseRequestToXml

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
@Test
public void parseRequestToXml() throws Exception {
    WinstromRequest request = WinstromRequest.builder()
            .issuedInvoice(IssuedInvoice.builder()
                    .company("code:ABCFIRM1#")
                    .documentType("code:FAKTURA")
                    .withoutItems(true)
                    .sumWithoutVat(BigDecimal.valueOf(1000))
                    .build()).build();

    ByteArrayOutputStream result = new ByteArrayOutputStream();
    Serializer serializer = Factory.persister();
    serializer.write(request, result);

    String xml = "<winstrom version=\"1.0\">\n" +
            "  <faktura-vydana>\n" +
            "    <typDokl>code:FAKTURA</typDokl>\n" +
            "    <firma>code:ABCFIRM1#</firma>\n" +
            "    <bezPolozek>true</bezPolozek>\n" +
            "    <sumDphZakl>1000</sumDphZakl>\n" +
            "  </faktura-vydana>\n" +
            "</winstrom>";
    assertThat(result.toString()).isXmlEqualTo(xml);
}
 
開發者ID:adleritech,項目名稱:flexibee,代碼行數:25,代碼來源:WinstromRequestTest.java

示例5: LocalDateIsParsed

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
@Test
public void LocalDateIsParsed() throws Exception {
    WinstromRequest envelope = WinstromRequest.builder()
            .issuedInvoice(IssuedInvoice.builder()
                    .issued(LocalDate.of(2017, 4, 2))
                    .build()).build();

    ByteArrayOutputStream result = new ByteArrayOutputStream();
    Serializer serializer = Factory.persister();
    serializer.write(envelope, result);

    String xml = "<winstrom version=\"1.0\">\n" +
            "    <faktura-vydana>\n" +
            "        <datVyst>2017-04-02</datVyst>\n" +
            "    </faktura-vydana>\n" +
            "</winstrom>";
    assertThat(result.toString()).isXmlEqualTo(xml);
}
 
開發者ID:adleritech,項目名稱:flexibee,代碼行數:19,代碼來源:IssuedInvoiceTest.java

示例6: paymentStatusIsParsedCorrectly

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
@Test
public void paymentStatusIsParsedCorrectly() throws Exception {
    String xml = "<winstrom version=\"1.0\">\n" +
            "    <faktura-vydana>\n" +
            "        <stavUhrK>stavUhr.uhrazenoRucne</stavUhrK>\n" +
            "    </faktura-vydana>\n" +
            "</winstrom>\n";

    WinstromRequest envelope = WinstromRequest.builder()
            .issuedInvoice(
                    IssuedInvoice.builder()
                            .paymentStatus(PaymentStatus.MANUALLY)
                            .build()
            ).build();

    ByteArrayOutputStream result = new ByteArrayOutputStream();
    Serializer serializer = Factory.persister();
    serializer.write(envelope, result);

    assertThat(result.toString()).isXmlEqualTo(xml);
}
 
開發者ID:adleritech,項目名稱:flexibee,代碼行數:22,代碼來源:IssuedInvoiceTest.java

示例7: flush

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
public void flush() {
		Serializer serializer = new Persister();
		Testsuite example = new Testsuite(clazz, 0f);
		for (Entry<String, Double> entry : entries.entrySet()) {
			example.getTestcases().add(new Testcase(entry.getKey(), clazz.getName(), String.valueOf(entry.getValue()/(double)1000)));
		}
		File reportFile = new File("target", "TEST-" + clazz.getName() + ".performance.xml");
		try {
//			serializer.write(example, System.out);
			serializer.write(example, reportFile);
		} catch (Exception e) {
			log.error("Error while saving {" + reportFile.getAbsolutePath() + "} for {" + clazz.getName() + "}", e);
		}


	}
 
開發者ID:gentics,項目名稱:mesh,代碼行數:17,代碼來源:StopWatchLogger.java

示例8: selected

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
@Override
public void selected(Array<FileHandle> files) {
    File file = files.first().file();
    if(!file.exists() || file.canWrite()) {
        Serializer serializer = new Persister();
        try {
            serializer.write(ChiptuneTracker.getInstance().getData(), file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(dataManager.getCurrentFile() == null) {
            dataManager.setCurrentFile(new StringBuilder());
        }
        dataManager.getCurrentFile().setLength(0);
        dataManager.getCurrentFile().append(file.getAbsolutePath());
        ChiptuneTracker.getInstance().setChangeData(false);
        additionalActions();
    }
    else {
        Dialogs.showErrorDialog(ChiptuneTracker.getInstance().getAsciiTerminal().getStage(), "Unable to write in the file !");
    }
    ((View) ChiptuneTracker.getInstance().getScreen()).setListActorTouchables(Touchable.enabled);
}
 
開發者ID:julianmaster,項目名稱:ChiptuneTracker,代碼行數:24,代碼來源:SaveFileListener.java

示例9: save

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
public void save() throws Exception {
	if(currentFile != null) {
		File file = new File(currentFile.toString());
		if(file.canWrite()) {
			Serializer serializer = new Persister();
			serializer.write(ChiptuneTracker.getInstance().getData(), file);
			ChiptuneTracker.getInstance().setChangeData(false);
		}
		else {
			throw new IOException("Unable to write in the file !");
		}
	}
	else {
		saveAs();
	}
}
 
開發者ID:julianmaster,項目名稱:ChiptuneTracker,代碼行數:17,代碼來源:DataManager.java

示例10: testSerialization

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
public void testSerialization() throws Exception{
   Serializer s = new Persister();
   StringWriter sw = new StringWriter();     
         
   String serializedForm =    "<test4>\n" + 
                        "   <single-element class=\"org.simpleframework.xml.core.Test4_2Test$MyElementC\"/>\n" +
                        "</test4>";
   System.out.println(serializedForm);
   System.out.println();
   
   Test4_2 o = s.read(Test4_2.class, serializedForm);
   
   //FIXME read ignores the class statement

   MyElementC ec = (MyElementC) o.element;
   
   sw.getBuffer().setLength(0);
   s.write(new Test4_2(new MyElementC()), sw);
   //FIXME it would be great, if this worked. Actually it works for ElementUnionLists.
   System.out.println(sw.toString());
   System.out.println();

}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:24,代碼來源:Test4_2Test.java

示例11: save

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
public static void save(
        @Nonnull Serializer serializer,
        @Nonnull OutputStream out,
        @Nonnull Object value, boolean compress) throws IOException {
    try {
        if (compress)
            out = new GZIPOutputStream(out);                       // Output (compressor)

        Object serializedValue = wrap(value);
        serializer.write(serializedValue, out);
        out.close();
    } catch (Exception e) {
        Throwables.propagateIfPossible(e, IOException.class);
        throw new IOException(e);
    }
}
 
開發者ID:shevek,項目名稱:simple-xml-serializers,代碼行數:17,代碼來源:PersisterUtils.java

示例12: init

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
public static void init() throws Exception{
	String configuration_filepath = System.getProperty("application.data.path")+"/"+System.getProperty("application.name")+".cfg.xml";
	Serializer serializer = new Persister();
	File file = new File(configuration_filepath);
	if(file.exists()){
		instance = serializer.read(Configuration.class, file);
	}else{
		instance = serializer.read(Configuration.class, Configuration.class.getResourceAsStream("/"+System.getProperty("application.name")+".default.cfg.xml"));
		logger.warn("Configuration file "+configuration_filepath+" not found. Using default configuration.");
		file.getParentFile().mkdirs();
		file.createNewFile();
		serializer.write(instance, file);
		logger.info("Configuration file "+configuration_filepath+" created.");
	}
	instance.datapath = System.getProperty("application.data.path");
	instance.applicationName = System.getProperty("application.name");
}
 
開發者ID:enolgor,項目名稱:webapp-stack,代碼行數:18,代碼來源:Configuration.java

示例13: testReplace

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
public void testReplace() throws Exception{
   Serializer s = new Persister();
   StringWriter sw = new StringWriter();
   s.write(new Test1A(null), sw);      
   String serializedForm = sw.toString();
   System.out.println(serializedForm);
   System.out.println();
   Test1 o = s.read(Test1.class, serializedForm);
   
   sw.getBuffer().setLength(0);
   
   //Unnecessary constructor exception a write, note that this happens with the default constructor only (see above)
  // s.write(new Test1B(), sw);    
   serializedForm = sw.toString();
   System.out.println(serializedForm);
  // o = s.read(Test1.class, serializedForm);
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:18,代碼來源:Test1_ReplaceTest.java

示例14: testSuperType

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
public void testSuperType() throws Exception {
   Map<String, String> clazMap = new HashMap<String, String> ();
   
   clazMap.put("subtype1", SubType1.class.getName());
   clazMap.put("subtype2", SubType2.class.getName());
   
   Visitor visitor = new ClassToNamespaceVisitor(false);
   Strategy strategy = new VisitorStrategy(visitor);
   Serializer serializer = new Persister(strategy);
   MyMap map = new MyMap();
   SubType1 subtype1 = new SubType1();
   SubType2 subtype2 = new SubType2();
   StringWriter writer = new StringWriter();
   
   subtype1.text = "subtype1";
   subtype2.superType = subtype1;
   
   map.getInternalMap().put("one", subtype1);
   map.getInternalMap().put("two", subtype2);

   serializer.write(map, writer); 
   serializer.write(map, System.out); 
   serializer.read(MyMap.class, writer.toString());
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:25,代碼來源:SuperTypeTest.java

示例15: testWrapper

import org.simpleframework.xml.Serializer; //導入方法依賴的package包/類
public void testWrapper() throws Exception{
   Strategy strategy = new AnnotationStrategy();
   Serializer serializer = new Persister(strategy);
   Entry entry = new Entry("name", "value");
   EntryHolder holder = new EntryHolder(entry, "test", 10);
   StringWriter writer = new StringWriter();
   serializer.write(holder, writer);
   System.out.println(writer.toString());
   serializer.read(EntryHolder.class, writer.toString());
   System.err.println(writer.toString());
   String sourceXml = writer.toString();
   assertElementExists(sourceXml, "/entryHolder");
   assertElementHasAttribute(sourceXml, "/entryHolder", "code", "10");
   assertElementExists(sourceXml, "/entryHolder/entry");
   assertElementExists(sourceXml, "/entryHolder/entry/name");
   assertElementHasValue(sourceXml, "/entryHolder/entry/name", "name");
   assertElementExists(sourceXml, "/entryHolder/entry/value");
   assertElementHasValue(sourceXml, "/entryHolder/entry/value", "value");
   assertElementExists(sourceXml, "/entryHolder/name");
   assertElementHasValue(sourceXml, "/entryHolder/name", "test");
}
 
開發者ID:ngallagher,項目名稱:simplexml,代碼行數:22,代碼來源:HideEnclosingConverterTest.java


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