/** * Serializes this gradebook archive into an xml document */ 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; }
/** * @param file */ public void save(String file) { try { //"D:/Test.xml" FileOutputStream out = new FileOutputStream(file); XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(out)); for (PluginDescription pb : internalIdToPluginDescription.values()) { encoder.writeObject(pb); encoder.flush(); } out.close(); } catch (Exception e) { e.printStackTrace(); } }
public static String toXml(final Object o) { ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLEncoder e = new XMLEncoder(out); e.writeObject(o); e.flush(); e.close(); return new String(out.toByteArray()); } }
public static String toXml(final Object o) { ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLEncoder e = new XMLEncoder(out); e.writeObject(o); e.flush(); e.close(); return new String(out.toByteArray()); }
protected byte[] encode() { ByteArrayOutputStream os = new ByteArrayOutputStream(); XMLEncoder e = new XMLEncoder(os); e.writeObject(multiSplitPaneModelRoot); e.flush(); e.close(); return os.toByteArray(); }
public byte[] toBytes(String key, Object value) { ByteArrayOutputStream bo = new ByteArrayOutputStream(); XMLEncoder xe = new XMLEncoder(bo); try { xe.writeObject(value); xe.flush(); } finally { xe.close(); } return bo.toByteArray(); }
public byte[] toBytes(String key, Object value) { ByteArrayOutputStream bo = new ByteArrayOutputStream(); XMLEncoder xe = new XMLEncoder(bo); try { xe.writeObject(value); xe.flush(); } finally { xe.close(); } return bo.toByteArray(); }
@Override public boolean save() { FileOutputStream out = null; try { out = new FileOutputStream(file); } catch (FileNotFoundException ex) { Logger.getLogger(ConfigurationFileImpl.class.getName()). log(Level.SEVERE, null, ex); try { out.close(); } catch (Exception ex1) { Logger.getLogger(ConfigurationFileImpl.class.getName()). log(Level.SEVERE, null, ex1); } return false; } XMLEncoder e = new XMLEncoder(out); e.writeObject(properties); e.flush(); e.close(); return true; }
private void save() { // no file specified, saving/loading disabled if (cacheLocation == null) { return; } FileOutputStream out = null; try { out = new FileOutputStream(cacheLocation); } catch (FileNotFoundException ex) { Logger.getLogger(RecentFilesManager.class.getName()). log(Level.SEVERE, null, ex); try { out.close(); } catch (Exception ex1) { Logger.getLogger(RecentFilesManager.class.getName()). log(Level.SEVERE, null, ex1); } return; } XMLEncoder e = new XMLEncoder(out); e.writeObject(recentSessions); e.flush(); e.close(); }
protected void flush() { XMLEncoder encoder = null; try { encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream( file))); encoder.writeObject(next); writeGroups(encoder); writeUsers(encoder); encoder.flush(); } catch (IOException ioe) { throw new RuntimeException(ioe); } finally { Misc.close(encoder); } }
Object1 obj = new Object1(); obj.setName("Girish"); obj.setAccount("3456"); obj.setCity("Ahmedabad"); FileOutputStream f =new FileOutputStream("Tmp.txt"); XMLEncoder ob =new XMLEncoder (f); ob.writeObject(obj); ob.flush();
public static byte[] objectsToByteArray (Object[] objects) throws ByteException { java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream(); java.beans.XMLEncoder encoder = new java.beans.XMLEncoder(os); try { for (int i=0; i<objects.length; i++) { if (objects[i] == null) continue; encoder.writeObject(objects[i]); encoder.flush(); } } catch (final Throwable t) { throw new ByteException ("Failed to encode objects", t); } return os.toByteArray(); }
private static void saveRequests() { File f = new File( VRL.getPropertyFolderManager().getPluginUpdatesFolder(), ".uninstall-requests.xml"); XMLEncoder e = null; try { e = new XMLEncoder(new FileOutputStream(f)); e.writeObject(requests); } catch (FileNotFoundException ex) { Logger.getLogger(UninstallPluginController.class.getName()). log(Level.SEVERE, null, ex); } finally { if (e != null) { try { e.flush(); e.close(); } catch (Exception ex) { // } } } }
NPair fe = new NPair(); fe.setNumber1(12); fe.setNumber2(13); FileOutputStream fos1 = new FileOutputStream("d:\\ser.xml"); java.beans.XMLEncoder xe1 = new java.beans.XMLEncoder(fos1); xe1.writeObject(fe); xe1.flush(); xe1.close();
/** * permet de sauvegarder au format XML un fichier de configuration * @param file nom du fichier de configuration a créer * @throws Exception */ public void serializeXMLToObject(String file) throws FileNotFoundException, IOException{ FileOutputStream os = new FileOutputStream(file); XMLEncoder encoder = new XMLEncoder(os); try{ encoder.writeObject(this); encoder.flush(); } finally{ encoder.close(); } } //Exemple d'option a lancer pour creer un fichier XML de configuration
String[][][] foo = new String[3][4][5]; foo[0][0][0] = "a"; foo[2][3][4] = "z"; XMLEncoder encoder = new XMLEncoder(System.out); encoder.writeObject(foo); encoder.flush(); encoder.close();
public static Component makeDeepCopy(Component clone) { XMLEncoder e = null; XMLDecoder d = null; try { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); e = new XMLEncoder(byteOut); e.writeObject(clone); e.flush(); ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut .toByteArray()); d = new XMLDecoder(byteIn); return (Component) d.readObject(); } catch (Exception eee) { eee.printStackTrace(); throw (eee); } finally { if (e != null) { e.close(); } if (d != null) { d.close(); } } }
public static Component makeDeepCopy(Component clone) throws Exception { XMLEncoder e = null; XMLDecoder d = null; try { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); e = new XMLEncoder(byteOut); e.writeObject(clone); e.flush(); ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut .toByteArray()); d = new XMLDecoder(byteIn); return (Component) d.readObject(); } catch (Exception eee) { eee.printStackTrace(); throw (eee); } finally { if (e != null) { e.close(); } if (d != null) { d.close(); } } }
protected void saveBar(XMLWriter writer, MyDoggyToolWindowBar toolWindowBar) throws SAXException { AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute(null, "anchor", null, null, toolWindowBar.getAnchor().toString()); attributes.addAttribute(null, "dividerSize", null, null, String.valueOf(toolWindowBar.getDividerSize())); attributes.addAttribute(null, "aggregateMode", null, null, String.valueOf(toolWindowBar.isAggregateMode())); writer.startElement("toolWindowBar", attributes); // Check for model if (toolWindowBar.getToolWindows().length > 0) { writer.startElement("layout"); ByteArrayOutputStream os = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(os); encoder.writeObject(toolWindowBar.getLayout()); encoder.flush(); encoder.close(); String model = os.toString(); writer.cdata(model.substring(model.indexOf('\n'))); writer.endElement("layout"); } writer.endElement("toolWindowBar"); }
/** * {@inheritDoc} */ @Override public <T> int serialize(T obj, Class<T> type, OutputStream out) throws IOException { out = new CountingOutputStream(new BufferedOutputStream(out, getBufferSize())); EL el = new EL(); XMLEncoder enc = new XMLEncoder(out); try { enc.setExceptionListener(el); enc.writeObject(obj); enc.flush(); } finally { if (isCloseEnabled()) { enc.close(); } } IOException ioe = el.getIOException(); if (ioe != null) { throw ioe; } return ((CountingOutputStream)out).getCount(); }