/** * Creates an ObjectOutputStream that serializes a stream of objects to the writer using * XStream. * <p> * To change the name of the root element (from <object-stream>), use * {@link #createObjectOutputStream(java.io.Writer, String)}. * </p> * * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, * String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.0.3 */ public ObjectOutputStream createObjectOutputStream(HierarchicalStreamWriter writer) throws IOException { return createObjectOutputStream(writer, "object-stream"); }
/** * Creates an ObjectOutputStream that serializes a stream of objects to the writer using * XStream. * <p> * Because an ObjectOutputStream can contain multiple items and XML only allows a single * root node, the stream must be written inside an enclosing node. * </p> * <p> * It is necessary to call ObjectOutputStream.close() when done, otherwise the stream will * be incomplete. * </p> * <h3>Example</h3> * * <pre> * ObjectOutputStream out = xstream.createObjectOutputStream(aWriter, "things"); * out.writeInt(123); * out.writeObject("Hello"); * out.writeObject(someObject) * out.close(); * </pre> * * @param writer The writer to serialize the objects to. * @param rootNodeName The name of the root node enclosing the stream of objects. * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.0.3 */ public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWriter writer, final String rootNodeName) throws IOException { return createObjectOutputStream(writer, rootNodeName, null); }
/** * Creates an ObjectOutputStream that serializes a stream of objects to the writer using * XStream. * * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, * String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.0.3 */ public ObjectOutputStream createObjectOutputStream(Writer writer, String rootNodeName) throws IOException { return createObjectOutputStream( hierarchicalStreamDriver.createWriter(writer), rootNodeName); }
/** * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream * using XStream. * * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, * String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.3 */ public ObjectOutputStream createObjectOutputStream(OutputStream out, String rootNodeName) throws IOException { return createObjectOutputStream( hierarchicalStreamDriver.createWriter(out), rootNodeName); }
/** * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream * using XStream. * <p> * To change the name of the root element (from <object-stream>), use * {@link #createObjectOutputStream(java.io.Writer, String)}. * </p> * * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, * String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.3 */ public ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException { return createObjectOutputStream( hierarchicalStreamDriver.createWriter(out), "object-stream"); }
/** * Creates an ObjectOutputStream that serializes a stream of objects to the writer using * XStream. * <p> * To change the name of the root element (from <object-stream>), use * {@link #createObjectOutputStream(java.io.Writer, String)}. * </p> * * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, * String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.0.3 */ public ObjectOutputStream createObjectOutputStream(Writer writer) throws IOException { return createObjectOutputStream( hierarchicalStreamDriver.createWriter(writer), "object-stream"); }
/** * Serialize an object including the XStream to the given Writer as pretty-printed XML. * <p> * Warning: XStream will serialize itself into this XML stream. To read such an XML code, you * should use {@link XStreamer#fromXML(Reader)} or one of the other overloaded * methods. Since a lot of internals are written into the stream, you cannot expect to use such * an XML to work with another XStream version or with XStream running on different JDKs and/or * versions. We have currently no JDK 1.3 support, nor will the PureReflectionConverter work * with a JDK less than 1.5. * </p> * * @throws IOException if an error occurs reading from the Writer. * @throws com.thoughtworks.xstream.XStreamException if the object cannot be serialized * @since 1.2 */ public void toXML(final XStream xstream, final Object obj, final Writer out) throws IOException { final XStream outer = new XStream(); XStream.setupDefaultSecurity(outer); final ObjectOutputStream oos = outer.createObjectOutputStream(out); try { oos.writeObject(xstream); oos.flush(); xstream.toXML(obj, out); } finally { oos.close(); } }
private static void writeAlertTypes(String dirName) { XStream xs = new XStream(); xs.alias("alert", Alert.class); try(ObjectOutputStream out = xs.createObjectOutputStream(new FileWriter(dirName + "/alert_types.xml"), "alerts");) { for (Field f : AlertManager.class.getFields()) { if (f.getClass().isAssignableFrom(Number.class)) { String name = f.getName().substring(11); Alert alert = new Alert(name, f.getInt(null)); out.writeObject(alert); } } } catch (IOException e) { s_logger.error("Failed to create output stream to write an alert types ", e); } catch (IllegalAccessException e) { s_logger.error("Failed to read alert fields ", e); } }
(new File(rootAdminDirName)).mkdirs(); ObjectOutputStream out = xs.createObjectOutputStream(new FileWriter(s_dirName + "/commands.xml"), "commands"); ObjectOutputStream rootAdmin = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + "apiSummary.xml"), "commands"); ObjectOutputStream rootAdminSorted = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + "apiSummarySorted.xml"), "commands"); writeCommand(rootAdmin, key); ObjectOutputStream singleRootAdminCommandOs = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + key + ".xml"), "command"); writeCommand(singleRootAdminCommandOs, key); singleRootAdminCommandOs.close();
public String getEvents() { final XStream xstream = new XStream(); StringWriter writer = new StringWriter(); try { final ObjectOutputStream out = xstream.createObjectOutputStream(writer); out.writeObject( this.events ); out.close(); } catch (Throwable t) { throw new RuntimeException("Unable to create event output: " + t.getMessage()); } return writer.toString(); }
/** * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream. * * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.0.3 */ public ObjectOutputStream createObjectOutputStream(final Writer writer, final String rootNodeName) throws IOException { return createObjectOutputStream(hierarchicalStreamDriver.createWriter(writer), rootNodeName); }
/** * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream using XStream. * * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.3 */ public ObjectOutputStream createObjectOutputStream(final OutputStream out, final String rootNodeName) throws IOException { return createObjectOutputStream(hierarchicalStreamDriver.createWriter(out), rootNodeName); }
/** * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream using * XStream. * * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.3 */ public ObjectOutputStream createObjectOutputStream(OutputStream out, String rootNodeName) throws IOException { return createObjectOutputStream(hierarchicalStreamDriver.createWriter(out), rootNodeName); }
public String toXML(final Object object) { final StringWriter stringWriter = new StringWriter(); try (final ObjectOutputStream out = XSTREAM.createObjectOutputStream(stringWriter)){ out.writeObject(object); } catch (IOException e) { throw new BonitaRuntimeException("Unable to serialize object " + object, e); } return stringWriter.toString(); }
/** * Creates an ObjectOutputStream that serializes a stream of objects to the writer using * XStream. * * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.0.3 */ public ObjectOutputStream createObjectOutputStream(Writer writer, String rootNodeName) throws IOException { return createObjectOutputStream(hierarchicalStreamDriver.createWriter(writer), rootNodeName); }
public String toXML(final Object object) { final StringWriter stringWriter = new StringWriter(); try (final ObjectOutputStream out = XSTREAM.createObjectOutputStream(stringWriter)){ out.writeObject(object); } catch (IOException e) { throw new BonitaRuntimeException("Unable to serialize object " + object, e); } return stringWriter.toString(); }
public String toXML(final Object object) { final StringWriter stringWriter = new StringWriter(); try (final ObjectOutputStream out = XSTREAM.createObjectOutputStream(stringWriter)){ out.writeObject(object); } catch (IOException e) { throw new BonitaRuntimeException("Unable to serialize object " + object, e); } return stringWriter.toString(); }
public String toXML(final Object object) { final StringWriter stringWriter = new StringWriter(); try (final ObjectOutputStream out = XSTREAM.createObjectOutputStream(stringWriter)){ out.writeObject(object); } catch (IOException e) { throw new BonitaRuntimeException("Unable to serialize object " + object, e); } return stringWriter.toString(); }
/** * Prints out a document-formats.xml from the {@link DefaultDocumentFormatRegistry} */ public static void main(String[] args) throws IOException { DefaultDocumentFormatRegistry registry = new DefaultDocumentFormatRegistry(); XStream xstream = createXStream(); ObjectOutputStream outputStream = xstream.createObjectOutputStream(new OutputStreamWriter(System.out), "document-formats"); for (Iterator iterator = registry.getDocumentFormats().iterator(); iterator.hasNext();) { outputStream.writeObject(iterator.next()); } outputStream.close(); } }
@Override public void resetOutput() throws IOException { if (file == null) { createTempFile(); } closeOutput(); outputStream = new XStream().createObjectOutputStream(new FileWriter(file)); for (String name : SimonManager.simonNames()) { SimonManager.getSimon(name).reset(); } }