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

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

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

XMLEncoder.setExceptionListener介绍

暂无

代码示例

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

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

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

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

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

e.setExceptionListener(listener);
e.writeObject(in);
e.close();

代码示例来源:origin: com.miglayout/miglayout-core

/** Writes the object and CLOSES the stream. Uses the persistence delegate registered in this class.
 * @param os The stream to write to. Will be closed.
 * @param o The object to be serialized.
 * @param listener The listener to receive the exceptions if there are any. If <code>null</code> not used.
 */
static void writeXMLObject(OutputStream os, Object o, ExceptionListener listener)
{
  ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
  Thread.currentThread().setContextClassLoader(LayoutUtil.class.getClassLoader());
  XMLEncoder encoder = new XMLEncoder(os);
  if (listener != null)
    encoder.setExceptionListener(listener);
  encoder.writeObject(o);
  encoder.close();    // Must be closed to write.
  Thread.currentThread().setContextClassLoader(oldClassLoader);
}

代码示例来源:origin: net.sourceforge.jadex/jadex-platform-base

/**
   *  Encode data with the codec.
   *  @param val The value.
   *  @return The encoded object.
   */
  public synchronized byte[] encode(Object val, ClassLoader classloader, Map<Class<?>, Object[]> info)
  {
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    XMLEncoder e = new XMLEncoder(bs);
    e.setExceptionListener(new ExceptionListener()
    {
      public void exceptionThrown(Exception e)
      {
        System.out.println("XML encoding ERROR: ");
        e.printStackTrace();
      }
    });
    Thread.currentThread().setContextClassLoader(classloader);
//        System.err.println("encoding with class loader: "+Thread.currentThread()+", "+Thread.currentThread().getContextClassLoader());
    e.writeObject(val);
    e.close();
    return bs.toByteArray();
  }

代码示例来源:origin: org.slf4j/slf4j-ext

/**
 * Serialize all the EventData items into an XML representation.
 * 
 * @param map the Map to transform
 * @return an XML String containing all the EventData items.
 */
public static String toXML(Map<String, Object> map) {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try {
    XMLEncoder encoder = new XMLEncoder(baos);
    encoder.setExceptionListener(new ExceptionListener() {
      public void exceptionThrown(Exception exception) {
        exception.printStackTrace();
      }
    });
    encoder.writeObject(map);
    encoder.close();
    return baos.toString();
  } catch (Exception e) {
    e.printStackTrace();
    return null;
  }
}

代码示例来源:origin: net.sourceforge.jadex/jadex-platform-base

/**
   *  Encode an object.
   *  @param obj The object.
   *  @throws IOException
   */
//    public byte[] encode(Object val, ClassLoader classloader)
  public Object encode(Object val, ClassLoader classloader)
  {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLEncoder enc = new XMLEncoder(baos);
    enc.setExceptionListener(new ExceptionListener()
    {
      public void exceptionThrown(Exception e)
      {
        System.out.println("XML encoding ERROR: ");
        e.printStackTrace();
      }
    });
    enc.writeObject(val);
    enc.close();
    try{baos.close();} catch(Exception e) {}
    return baos.toByteArray();
  }

代码示例来源:origin: violetumleditor/violetumleditor

/**
 * Creates a new instance of XML Encoder pre-configured for Violet beans serailization
 * 
 * @param out
 * @return configured encoder
 */
private XMLEncoder getXMLEncoder(OutputStream out)
{
  XMLEncoder encoder = new XMLEncoder(out);

  encoder.setExceptionListener(new ExceptionListener()
  {
    public void exceptionThrown(Exception ex)
    {
      ex.printStackTrace();
    }
  });
  configure(encoder);
  return encoder;
}

代码示例来源:origin: be.yildiz-games/common-file-xml

/**
 * Write an object into a XML file.
 *
 * @param o Object to persist.
 */
@Override
public void writeToFile(final T o) {
  try (OutputStream fos = Files.newOutputStream(this.file)) {
    try (XMLEncoder encoder = new XMLEncoder(fos)) {
      encoder.setExceptionListener(FileCreationException::new);
      encoder.writeObject(o);
    }
  } catch (IOException e) {
    throw new FileCreationException(e);
  }
}

代码示例来源:origin: Unidata/thredds

beanEncoder.setExceptionListener(new ExceptionListener() {
 public void exceptionThrown(Exception exception) {
  System.out.println("XMLStore.save() got Exception: abort saving the preferences!");

代码示例来源:origin: edu.ucar/netcdf

beanEncoder.setExceptionListener(new ExceptionListener() {
 public void exceptionThrown(Exception exception) {
  System.out.println("XMLStore.save() got Exception: abort saving the preferences!");

代码示例来源:origin: com.jalalkiswani/jk-util

/**
 * To xml.
 *
 * @param obj
 *            the obj
 * @return the string
 */
// ////////////////////////////////////////////////////////////////////
public static String toXml(final Object obj) {
  final ByteArrayOutputStream out = new ByteArrayOutputStream();
  // XStream x = createXStream();
  // String xml = x.toXML(obj);
  // return xml;
  final XMLEncoder e = new XMLEncoder(out);
  e.setExceptionListener(new XmlEncoderExceptionListener());
  // e.setPersistenceDelegate(Object.class, new MyPersistenceDelegate());
  e.writeObject(obj);
  e.close();
  return out.toString();
  // return null;
}

代码示例来源:origin: org.nuiton/nuiton-widgets

e = new XMLEncoder(bst);
  e.setPersistenceDelegate(Rectangle.class, new RectanglePD());
  e.setExceptionListener(el);
  e.writeObject(states);
} finally {

代码示例来源:origin: net.sf.jstuff/jstuff-core

/**
* @see XMLEncoder
*/
@SuppressWarnings("resource")
public static String bean2xml(final Object javaBean) throws SerializationException {
 Args.notNull("javaBean", javaBean);
 final ArrayList<Exception> exList = new ArrayList<Exception>(2);
 final FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
 final XMLEncoder encoder = new XMLEncoder(bos);
 encoder.setExceptionListener(new ExceptionListener() {
   public void exceptionThrown(final Exception ex) {
    exList.add(ex);
   }
 });
 encoder.writeObject(javaBean);
 encoder.close();
 if (exList.size() > 0)
   throw new SerializationException("An error occured during XML serialization", exList.get(0));
 return bos.toString();
}

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

代码示例来源:origin: net.java.dev.appframework/appframework

persistenceDelegatesInitialized = true;
e.setExceptionListener(el);
e.writeObject(bean);

代码示例来源:origin: jboss-switchyard/core

/**
 * {@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();
}

代码示例来源:origin: de.schlichtherle.truezip/truezip-file

enc.setExceptionListener(listener);
enc.writeObject(original);
enc.close();

代码示例来源:origin: org.apache.hadoop.hive/hive-exec

/**
 * Serialize the whole query plan.
 */
public static void serializeQueryPlan(QueryPlan plan, OutputStream out) {
 XMLEncoder e = new XMLEncoder(out);
 e.setExceptionListener(new ExceptionListener() {
  public void exceptionThrown(Exception e) {
   LOG.warn(org.apache.hadoop.util.StringUtils.stringifyException(e));
   throw new RuntimeException("Cannot serialize the query plan", e);
  }
 });
 // workaround for java 1.5
 e.setPersistenceDelegate(ExpressionTypes.class, new EnumDelegate());
 e.setPersistenceDelegate(GroupByDesc.Mode.class, new EnumDelegate());
 e.setPersistenceDelegate(Operator.ProgressCounter.class, new EnumDelegate());
 e.setPersistenceDelegate(org.datanucleus.sco.backed.Map.class, new MapDelegate());
 e.setPersistenceDelegate(org.datanucleus.sco.backed.List.class, new ListDelegate());
 e.writeObject(plan);
 e.close();
}

代码示例来源:origin: com.facebook.presto.hive/hive-apache

/**
 * Serialize the object. This helper function mainly makes sure that enums,
 * counters, etc are handled properly.
 */
private static void serializeObjectByJavaXML(Object plan, OutputStream out) {
 XMLEncoder e = new XMLEncoder(out);
 e.setExceptionListener(new ExceptionListener() {
  @Override
  public void exceptionThrown(Exception e) {
   LOG.warn(org.apache.hadoop.util.StringUtils.stringifyException(e));
   throw new RuntimeException("Cannot serialize object", e);
  }
 });
 // workaround for java 1.5
 e.setPersistenceDelegate(ExpressionTypes.class, new EnumDelegate());
 e.setPersistenceDelegate(GroupByDesc.Mode.class, new EnumDelegate());
 e.setPersistenceDelegate(java.sql.Date.class, new DatePersistenceDelegate());
 e.setPersistenceDelegate(Timestamp.class, new TimestampPersistenceDelegate());
 e.setPersistenceDelegate(org.datanucleus.store.types.backed.Map.class, new MapDelegate());
 e.setPersistenceDelegate(org.datanucleus.store.types.backed.List.class, new ListDelegate());
 e.setPersistenceDelegate(CommonToken.class, new CommonTokenDelegate());
 e.setPersistenceDelegate(Path.class, new PathDelegate());
 e.writeObject(plan);
 e.close();
}

相关文章