java.beans.XMLEncoder.writeObject()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(273)

本文整理了Java中java.beans.XMLEncoder.writeObject()方法的一些代码示例,展示了XMLEncoder.writeObject()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLEncoder.writeObject()方法的具体详情如下:
包路径:java.beans.XMLEncoder
类名称:XMLEncoder
方法名:writeObject

XMLEncoder.writeObject介绍

暂无

代码示例

代码示例来源: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

e.setPersistenceDelegate(File.class,
    new FilePersistenceDelegate());
e.writeObject(history);

代码示例来源: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

enc.setExceptionListener(listener);
Project p1 = new Project("foo");
enc.writeObject(p1);
enc.close();

代码示例来源:origin: oracle/opengrok

enc.setExceptionListener(listener);
Group g1 = new Group();
enc.writeObject(g1);
enc.close();

代码示例来源:origin: oracle/opengrok

XMLEncoder e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(testXML)));
e.setExceptionListener(listener);
e.writeObject(in);
e.close();

代码示例来源:origin: oracle/opengrok

enc.writeObject(cfg);

代码示例来源:origin: bobbylight/RSyntaxTextArea

XMLEncoder e = new XMLEncoder(new BufferedOutputStream(
              new FileOutputStream(xmlFile)));
  e.writeObject(template);
  e.close();
} catch (IOException ioe) {

代码示例来源: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.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: 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: 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: httl/httl

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();
}

代码示例来源:origin: net.sf.squirrel-sql/squirrel-sql

/**
* @see net.sourceforge.squirrel_sql.client.update.xmlbeans.UpdateXmlSerializer#write(net.sourceforge.squirrel_sql.client.update.xmlbeans.ChangeListXmlBean, java.lang.String)
*/
public void write(ChangeListXmlBean changeBean, String filename)
   throws FileNotFoundException {
 XMLEncoder os = getXmlEncoder(filename);
 os.writeObject(changeBean);
 os.close();
}

代码示例来源:origin: com.github.httl/httl

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();
}

代码示例来源: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();
}

相关文章