List of usage examples for java.beans XMLEncoder flush
public void flush()
From source file:Main.java
/** * Serializes an object into an xml file * /*from w w w.j a va2s. c om*/ * @param object object to serialize * @param fileName path to file */ public static void encodeToFile(Object object, String fileName) throws FileNotFoundException, IOException { XMLEncoder encoder = new XMLEncoder(new FileOutputStream(fileName)); try { encoder.writeObject(object); encoder.flush(); } finally { encoder.close(); } }
From source file:com.npower.dl.FirmwareMimeTypeHelper.java
public static void save(File file) throws IOException { FileOutputStream out = new FileOutputStream(file); XMLEncoder xmlEncoder = new XMLEncoder(out); xmlEncoder.writeObject(mimeTypes);/* ww w . java2 s.c o m*/ xmlEncoder.flush(); xmlEncoder.close(); out.close(); }
From source file:com.db4o.sync4o.ui.Db4oSyncSourceConfigPanel.java
private static void showTestUI() { // Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); // Create and set up the window. JFrame frame = new JFrame("Db4oSyncSourceConfigPanel Test Harness"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create and set up the content pane. final Db4oSyncSource source = new Db4oSyncSource(); Db4oSyncSourceConfigPanel p = new Db4oSyncSourceConfigPanel(); p.setManagementObject(new SyncSourceManagementObject(source, null, null, null, null)); p.updateForm();// w ww.j a v a 2 s .c o m p.setOpaque(true); // content panes must be opaque frame.setContentPane(p); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { XMLEncoder encoder = null; try { FileOutputStream s = new FileOutputStream("test.xml"); encoder = new XMLEncoder(s); encoder.setExceptionListener(new ExceptionListener() { public void exceptionThrown(Exception exception) { exception.printStackTrace(); } }); } catch (FileNotFoundException e) { e.printStackTrace(); System.exit(-1); } encoder.writeObject((Object) source); encoder.flush(); encoder.close(); } }); // Display the window. frame.pack(); frame.setVisible(true); }
From source file:com.jaspersoft.jasperserver.export.modules.repository.OlapUnitViewOptionsDataProvider.java
public InputStream getData(ExporterModuleContext exportContext, Resource resource) { OlapUnit unit = (OlapUnit) resource; InputStream dataStream;//from ww w . j av a 2 s. co m Object viewOptions = unit.getOlapViewOptions(); if (viewOptions == null) { dataStream = null; } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder e = new XMLEncoder(new BufferedOutputStream(baos)); e.writeObject(unit.getOlapViewOptions()); e.flush(); e.close(); dataStream = new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray())); } return dataStream; }
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 w ww . j a va 2 s .c om*/ 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.settings4j.objectresolver.JavaXMLBeansObjectResolverTest.java
private byte[] objectToContent(final Object value) { final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final XMLEncoder encoder = new XMLEncoder(byteArrayOutputStream); encoder.setExceptionListener(new LogEncoderExceptionListener(value)); LOG.debug("START Writing Object {} with XMLEncoder", value.getClass().getName()); encoder.writeObject(value);/*from www.j av a2s .c o m*/ LOG.debug("FINISH Writing Object {} with XMLEncoder", value.getClass().getName()); encoder.flush(); encoder.close(); return byteArrayOutputStream.toByteArray(); }
From source file:org.sakaiproject.tool.gradebook.GradebookArchive.java
/** * Serializes this gradebook archive into an xml document *//*from w w w .j a v a2s . c o m*/ 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.shaman.database.Benchmark.java
/** * prints the file size/*w ww. jav a 2 s . co m*/ * @param roots the roots from the different passes */ private void printFileSizes(Record... roots) throws IOException { //result array int size; String format = "%1$,11d"; System.out.println("passes database serial compressed xml"); //save it for (int i = 0; i < roots.length; i++) { Record root = roots[i]; System.out.print("pass " + (i + 1) + " "); //database ArrayOutput ao = new ArrayOutput(); Database db = new Database(root); db.save(ao, FailOnErrorHandler.INSTANCE); size = ao.getTotalSize(); System.out.printf(format, size); System.out.print("B "); //uncompressed serialization CountingOutputStream out = new CountingOutputStream(new NullOutputStream()); ObjectOutputStream dos = new ObjectOutputStream(out); dos.writeObject(root); dos.flush(); size = out.getCount(); System.out.printf(format, size); System.out.print("B "); //compressed serialization out.resetCount(); dos = new ObjectOutputStream(new GZIPOutputStream(out)); dos.writeObject(root); dos.flush(); size = out.getCount(); System.out.printf(format, size); System.out.print("B "); //xml out.resetCount(); XMLEncoder xml = new XMLEncoder(out); xml.writeObject(root); xml.flush(); size = out.getCount(); System.out.printf(format, size); System.out.println("B"); } }