List of usage examples for java.beans XMLEncoder writeObject
public void writeObject(Object o)
From source file:Roster.Rosters.java
private JSONObject toXML() { String xml = null;/*w w w .j a v a 2s . c o m*/ try { ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(out); encoder.writeObject(students); // serialize to XML encoder.close(); xml = out.toString(); // stringify } catch (Exception e) { } //System.out.println(xml.trim()); JSONObject jobt = XML.toJSONObject(xml); //System.out.println(jobt); return jobt; }
From source file:org.jumpmind.vaadin.ui.sqlexplorer.DefaultSettingsProvider.java
@Override public void save(Settings settings) { synchronized (getClass()) { File file = getSettingsFile(); FileOutputStream os = null; try {/*from ww w. ja v a2 s . com*/ os = new FileOutputStream(file, false); XMLEncoder encoder = new XMLEncoder(os); encoder.writeObject(settings); encoder.close(); this.settings = settings; } catch (Exception ex) { log.error(ex.getMessage(), ex); } finally { IOUtils.closeQuietly(os); } } }
From source file:org.seasar.cadhelin.ControllerMetadata.java
public void saveConverterSettings(OutputStream os) { XMLEncoder encoder = new XMLEncoder(os); encoder.writeObject(getConverters()); encoder.close();//ww w.java 2s . c o m }
From source file:PersistentFrameTest.java
public void save() { if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {// w w w . ja v a2 s. c om try { File file = chooser.getSelectedFile(); XMLEncoder encoder = new XMLEncoder(new FileOutputStream(file)); encoder.writeObject(frame); encoder.close(); } catch (IOException e) { JOptionPane.showMessageDialog(null, e); } } }
From source file:org.sakaiproject.tool.gradebook.GradebookArchive.java
/** * Serializes this gradebook archive into an xml document *///from w ww.java2 s . com public String archive() { if (log.isDebugEnabled()) log.debug("GradebookArchive.archive() called"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(baos)); encoder.writeObject(this); encoder.flush(); String xml = baos.toString(); if (log.isDebugEnabled()) log.debug("GradebookArchive.archive() finished"); return xml; }
From source file:org.geomajas.plugin.deskmanager.domain.types.XmlSerialisationType.java
private String toXmlString(Object value) { if (value == null) { return null; }//from w w w . ja v a 2 s .c o m try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(baos); encoder.writeObject(value); encoder.close(); String result = baos.toString(ENCODING); baos.close(); return result; } catch (IOException e) { e.printStackTrace(); IllegalArgumentException ex = new IllegalArgumentException("cannot disassemble the object", e); throw ex; } }
From source file:net.commerce.zocalo.experiment.config.SessionConfigurationTest.java
private byte[] writeObjToXmlBytes(Object config) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); // FileOutputStream fos = null; // try { // fos = new FileOutputStream("temp.xml"); // } catch (FileNotFoundException e) { // e.printStackTrace(); // }/*from w ww . java 2 s .c o m*/ // XMLEncoder fenc = new XMLEncoder(fos); // fenc.writeObject(config); // fenc.close(); XMLEncoder enc = new XMLEncoder(baos); enc.writeObject(config); enc.close(); return baos.toByteArray(); }
From source file:edu.wisc.my.stats.dao.xml.XmlQueryInformationDao.java
/** * @param queryInformationSet The Set of QueryInformation to persist to the specified XML file. *//*from www .j a va 2 s. co m*/ protected void writeQueryInformationSet(Set<QueryInformation> queryInformationSet) { final FileOutputStream fos; try { fos = new FileOutputStream(this.storeFile); } catch (FileNotFoundException fnfe) { final String errorMessage = "The specified storeFile='" + this.storeFile + "' could not be found."; this.logger.error(errorMessage, fnfe); throw new IllegalArgumentException(errorMessage, fnfe); } final BufferedOutputStream bos = new BufferedOutputStream(fos); final XMLEncoder xmlEncoder = new XMLEncoder(bos); try { xmlEncoder.writeObject(queryInformationSet); xmlEncoder.flush(); } finally { xmlEncoder.close(); } }
From source file:org.cesecore.util.HashMapTest.java
@SuppressWarnings("rawtypes") @Test/*from ww w. j av a 2 s. co m*/ public void testHashMapNormal() throws Exception { HashMap<String, Comparable> a = new HashMap<String, Comparable>(); a.put("foo0", Boolean.FALSE); a.put("foo1", "fooString"); a.put("foo2", Integer.valueOf(2)); a.put("foo3", Boolean.TRUE); // Write to XML ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(baos); encoder.writeObject(a); encoder.close(); String data = baos.toString("UTF8"); //log.error(data); XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(data.getBytes("UTF8"))); HashMap<?, ?> b = (HashMap<?, ?>) decoder.readObject(); decoder.close(); assertEquals(((Boolean) b.get("foo0")).booleanValue(), false); assertEquals(((Boolean) b.get("foo3")).booleanValue(), true); assertEquals(((String) b.get("foo1")), "fooString"); assertEquals(((Integer) b.get("foo2")).intValue(), 2); }
From source file:org.ejbca.ui.web.admin.certprof.ProfilesExportServlet.java
private byte[] getProfileBytes(UpgradeableDataHashMap profile) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(baos); encoder.writeObject(profile.saveData()); encoder.close();//from w ww . ja va 2s . c om byte[] ba = baos.toByteArray(); baos.close(); return ba; }