本文整理了Java中com.thoughtworks.xstream.XStream.createObjectOutputStream()
方法的一些代码示例,展示了XStream.createObjectOutputStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XStream.createObjectOutputStream()
方法的具体详情如下:
包路径:com.thoughtworks.xstream.XStream
类名称:XStream
方法名:createObjectOutputStream
[英]Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
To change the name of the root element (from <object-stream>), use #createObjectOutputStream(java.io.Writer,String).
[中]创建一个ObjectOutputStream,使用XStream将对象流序列化到编写器。
要更改根元素的名称(来自<object stream>),请使用#createObjectOutputStream(java.io.Writer,String)。
代码示例来源:origin: com.thoughtworks.xstream/xstream
/**
* 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");
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
/**
* 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);
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
/**
* 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);
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
/**
* 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);
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
/**
* 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");
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
/**
* 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");
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
/**
* 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();
}
}
代码示例来源:origin: apache/cloudstack
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);
}
}
代码示例来源:origin: apache/cloudstack
(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();
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.drools
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();
}
代码示例来源:origin: x-stream/xstream
/**
* 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);
}
代码示例来源:origin: x-stream/xstream
/**
* 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);
}
代码示例来源:origin: ovea-deprecated/jetty-session-redis
/**
* 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);
}
代码示例来源:origin: bonitasoft/bonita-engine
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();
}
代码示例来源:origin: ovea-deprecated/jetty-session-redis
/**
* 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);
}
代码示例来源:origin: bonitasoft/bonita-engine
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();
}
代码示例来源:origin: bonitasoft/bonita-engine
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();
}
代码示例来源:origin: bonitasoft/bonita-engine
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();
}
代码示例来源:origin: com.artofsolving/jodconverter
/**
* 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();
}
}
代码示例来源:origin: org.nuxeo.runtime/nuxeo-runtime-management
@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();
}
}
内容来源于网络,如有侵权,请联系作者删除!