本文整理了Java中java.beans.XMLEncoder.<init>()
方法的一些代码示例,展示了XMLEncoder.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLEncoder.<init>()
方法的具体详情如下:
包路径:java.beans.XMLEncoder
类名称:XMLEncoder
方法名:<init>
暂无
代码示例来源:origin: oracle/opengrok
public void encodeObject(OutputStream out) {
try (XMLEncoder e = new XMLEncoder(new BufferedOutputStream(out))) {
e.writeObject(this);
}
}
代码示例来源:origin: apache/shiro
/**
* Serializes the specified <code>source</code> into a byte[] array by using the
* {@link java.beans.XMLEncoder XMLEncoder} to encode the object out to a
* {@link java.io.ByteArrayOutputStream ByteArrayOutputStream}, where the resulting byte[] array is returned.
* @param source the Object to convert into a byte[] array.
* @return the byte[] array representation of the XML encoded output.
*/
public byte[] serialize(Object source) {
if (source == null) {
String msg = "argument cannot be null.";
throw new IllegalArgumentException(msg);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(bos));
encoder.writeObject(source);
encoder.close();
return bos.toByteArray();
}
代码示例来源:origin: oracle/opengrok
output = File.createTempFile("oghist", null, dir);
try (FileOutputStream out = new FileOutputStream(output);
XMLEncoder e = new XMLEncoder(new GZIPOutputStream(
new BufferedOutputStream(out)))) {
e.setPersistenceDelegate(File.class,
代码示例来源:origin: looly/hutool
/**
* 将可序列化的对象转换为XML写入文件,已经存在的文件将被覆盖<br>
* Writes serializable object to a XML file. Existing file will be overwritten
*
* @param dest 目标文件
* @param bean 对象
* @throws IOException IO异常
*/
public static void writeObjectAsXml(File dest, Object bean) throws IOException {
XMLEncoder xmlenc = null;
try {
xmlenc = new XMLEncoder(FileUtil.getOutputStream(dest));
xmlenc.writeObject(bean);
} finally {
// 关闭XMLEncoder会相应关闭OutputStream
IoUtil.close(xmlenc);
}
}
代码示例来源:origin: looly/hutool
/**
* 将可序列化的对象转换为XML写入文件,已经存在的文件将被覆盖<br>
* Writes serializable object to a XML file. Existing file will be overwritten
*
* @param dest 目标文件
* @param bean 对象
* @throws IOException IO异常
*/
public static void writeObjectAsXml(File dest, Object bean) throws IOException {
XMLEncoder xmlenc = null;
try {
xmlenc = new XMLEncoder(FileUtil.getOutputStream(dest));
xmlenc.writeObject(bean);
} finally {
// 关闭XMLEncoder会相应关闭OutputStream
IoUtil.close(xmlenc);
}
}
代码示例来源:origin: oracle/opengrok
/**
* Verify that encoding of Group class does not contain transient members.
* @throws Exception exception
*/
@Test
public void testTransientKeywordGroups() throws Exception {
Group foo = new Group("foo", "foo.*");
Group bar = new Group("bar", "bar.*");
Configuration cfg = new Configuration();
cfg.addGroup(foo);
foo.addGroup(bar);
cfg.addGroup(bar);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (XMLEncoder enc = new XMLEncoder(out)) {
enc.writeObject(cfg);
}
// In this test we are no so much interested in exceptions during the
// XML decoding as that is covered by the {@code serializationOrderTest}
// test.
try (ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray())) {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
Handler handler = new Handler();
saxParser.parse(new BufferedInputStream(in), handler);
}
}
代码示例来源:origin: oracle/opengrok
XMLEncoder enc = new XMLEncoder(out);
enc.setExceptionListener(listener);
Project p1 = new Project("foo");
代码示例来源:origin: oracle/opengrok
XMLEncoder enc = new XMLEncoder(out);
enc.setExceptionListener(listener);
Group g1 = new Group();
代码示例来源:origin: oracle/opengrok
XMLEncoder e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(testXML)));
e.setExceptionListener(listener);
e.writeObject(in);
代码示例来源:origin: oracle/opengrok
try (XMLEncoder enc = new XMLEncoder(out)) {
enc.writeObject(cfg);
代码示例来源:origin: bobbylight/RSyntaxTextArea
File xmlFile = new File(directory, template.getID() + ".xml");
try {
XMLEncoder e = new XMLEncoder(new BufferedOutputStream(
new FileOutputStream(xmlFile)));
e.writeObject(template);
代码示例来源:origin: stackoverflow.com
import java.beans.XMLEncoder;
import java.beans.XMLDecoder;
import java.io.*;
public class XMLSerializer {
public static void write(String[][] f, String filename) throws Exception{
XMLEncoder encoder =
new XMLEncoder(
new BufferedOutputStream(
new FileOutputStream(filename)));
encoder.writeObject(f);
encoder.close();
}
public static String[][] read(String filename) throws Exception {
XMLDecoder decoder =
new XMLDecoder(new BufferedInputStream(
new FileInputStream(filename)));
String[][] o = (String[][])decoder.readObject();
decoder.close();
return o;
}
}
代码示例来源:origin: net.sf.squirrel-sql/squirrel-sql
private XMLEncoder getXmlEncoder(String filename)
throws FileNotFoundException {
XMLEncoder result = null;
BufferedOutputStream os =
new BufferedOutputStream(new FileOutputStream(filename));
result = new XMLEncoder(os);
result.setPersistenceDelegate(ArtifactAction.class, enumDelegate);
return result;
}
}
代码示例来源:origin: com.globalmentor/globalmentor-core
/**
* Constructs an <code>XMLEncoder</code> and upgrades it to support other non-JavaBean classes.
* @param out The stream to which the XML representation of the objects will be sent.
* @return A new <code>XMLEncoder</code> which supports encoding of other other non-JavaBean classes.
* @see XMLEncoder
* @see #upgradeEncoder(Encoder)
*/
public static XMLEncoder createUpgradedXMLEncoder(OutputStream out) {
final XMLEncoder xmlEncoder = new XMLEncoder(out); //create a new XML encoder
upgradeEncoder(xmlEncoder); //upgrade the encoder
return xmlEncoder; //return the new upgraded encoder
}
代码示例来源:origin: org.ihtsdo/wb-api
protected XMLEncoder getEncoder(File changeset) throws FileNotFoundException {
XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(new File(
changeset.getParent(), changeset.getName() + outputSuffix))));
encoder.setPersistenceDelegate(UUID.class, new java.beans.PersistenceDelegate() {
protected Expression instantiate(Object oldInstance, Encoder out) {
return new Expression(oldInstance, oldInstance.getClass(), "fromString",
new Object[] { oldInstance.toString() });
}
});
return encoder;
}
代码示例来源:origin: openpnp/openpnp
public static String serialize(Object o) {
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
XMLEncoder xmlEncoder = new XMLEncoder(bOut);
xmlEncoder.writeObject(o);
xmlEncoder.close();
return bOut.toString();
}
代码示例来源:origin: net.sf.czsem/czsem-common
public static void saveToFile(String filename, Map<String, Object> map) throws IOException
{
FileOutputStream os = new FileOutputStream(filename);
XMLEncoder encoder = new XMLEncoder(os);
encoder.writeObject(map);
encoder.close();
os.close();
}
代码示例来源:origin: com.haulmont.thirdparty/glazedlists
/** {@inheritDoc} */
public void encode(Object source, OutputStream target) throws IOException {
XMLEncoder xmlOut = new XMLEncoder(target);
xmlOut.writeObject(source);
xmlOut.close();
}
代码示例来源:origin: stackoverflow.com
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();
代码示例来源:origin: com.facebook.presto.hive/hive-apache
public static void serialize(OutputStream out, Object o)
{
XMLEncoder e = new XMLEncoder(out);
e.setExceptionListener(new EL());
PTFUtils.addPersistenceDelegates(e);
e.writeObject(o);
e.close();
}
内容来源于网络,如有侵权,请联系作者删除!