本文整理匯總了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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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();
}
示例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);
}
}
示例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");
}
示例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);
}
示例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());
}
示例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");
}