类java.beans.ExceptionListener源码实例Demo

下面列出了怎么用java.beans.ExceptionListener的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: netcdf-java   文件: TestObjectEncode.java
@Test
public void testNodeChange() throws BackingStoreException, IOException {

  String filename = File.createTempFile("foo", "bar").getAbsolutePath();
  OutputStream objOS = new BufferedOutputStream(new FileOutputStream(filename, false));

  XMLEncoder beanEncoder = new XMLEncoder(objOS);
  beanEncoder.setExceptionListener(new ExceptionListener() {
    public void exceptionThrown(Exception exception) {
      System.out.println("XMLStore.save()");
      exception.printStackTrace();
    }
  });

  beanEncoder.writeObject(new java.awt.Rectangle(100, 200));
  beanEncoder.writeObject(new TesterBean());
  beanEncoder.close();
}
 
源代码2 项目: netbeans   文件: XMLBeanConvertor.java
public @Override void write(java.io.Writer w, final Object inst) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLEncoder e = new XMLEncoder(out);
    e.setExceptionListener(new ExceptionListener() {
        public @Override void exceptionThrown(Exception x) {
            Logger.getLogger(XMLBeanConvertor.class.getName()).log(Level.INFO, "Problem writing " + inst, x);
        }
    });
    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    try {
        // XXX would inst.getClass().getClassLoader() be more appropriate?
        ClassLoader ccl2 = Lookup.getDefault().lookup(ClassLoader.class);
        if (ccl2 != null) {
            Thread.currentThread().setContextClassLoader(ccl2);
        }
        e.writeObject(inst);
    } finally {
        Thread.currentThread().setContextClassLoader(ccl);
    }
    e.close();
    String data = new String(out.toByteArray(), "UTF-8");
    data = data.replaceFirst("<java", "<!DOCTYPE xmlbeans PUBLIC \"-//NetBeans//DTD XML beans 1.0//EN\" \"http://www.netbeans.org/dtds/xml-beans-1_0.dtd\">\n<java");
    w.write(data);
}
 
源代码3 项目: netcdf-java   文件: XMLStore.java
private XMLDecoder openBeanDecoder(InputStream objIS) {
  // filter stream for XMLDecoder
  XMLDecoder beanDecoder = new XMLDecoder(objIS, null, new ExceptionListener() {
    public void exceptionThrown(Exception e) {
      if (showDecoderExceptions)
        System.out.println("***XMLStore.read() got Exception= " + e.getClass().getName() + " " + e.getMessage());
      e.printStackTrace();
    }
  });

  return beanDecoder;
}
 
源代码4 项目: netcdf-java   文件: XMLStore.java
/**
 * Save the current state of the Preferences tree to the given OutputStream.
 */
public void save(OutputStream out) throws java.io.IOException {
  outputExceptionMessage = null;

  // the OutputMunger strips off the XMLEncoder header
  OutputMunger bos = new OutputMunger(out);
  PrintWriter pw = new PrintWriter(new OutputStreamWriter(bos, StandardCharsets.UTF_8));

  XMLEncoder beanEncoder = new XMLEncoder(bos);
  beanEncoder.setExceptionListener(new ExceptionListener() {
    public void exceptionThrown(Exception exception) {
      System.out.println("XMLStore.save() got Exception: abort saving the preferences!");
      exception.printStackTrace();
      outputExceptionMessage = exception.getMessage();
    }
  });

  pw.printf("<?xml version='1.0' encoding='UTF-8'?>%n");
  pw.printf("<preferences EXTERNAL_XML_VERSION='1.0'>%n");
  if (!rootPrefs.isUserNode())
    pw.printf("  <root type='system'>%n");
  else
    pw.printf("  <root type='user'>%n");

  Indent indent = new Indent(2);
  indent.incr();
  writeXmlNode(bos, pw, rootPrefs, beanEncoder, indent);
  if (outputExceptionMessage != null)
    throw new IOException(outputExceptionMessage);

  pw.printf("  </root>%n");
  pw.printf("</preferences>%n");
  pw.flush();
}
 
源代码5 项目: dragonwell8_jdk   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码6 项目: tds   文件: XMLStore.java
private XMLDecoder openBeanDecoder(InputStream objIS) {
  // filter stream for XMLDecoder
  XMLDecoder beanDecoder = new XMLDecoder(objIS, null, new ExceptionListener() {
    public void exceptionThrown(Exception e) {
      if (showDecoderExceptions)
        System.out.println("***XMLStore.read() got Exception= " + e.getClass().getName() + " " + e.getMessage());
      e.printStackTrace();
    }
  });

  // System.out.println("openBeanDecoder at "+objIS);
  return beanDecoder;
}
 
源代码7 项目: tds   文件: XMLStore.java
/**
 * Save the current state of the Preferences tree to the given OutputStream.
 */
public void save(OutputStream out) throws java.io.IOException {
  outputExceptionMessage = null;

  // the OutputMunger strips off the XMLEncoder header
  OutputMunger bos = new OutputMunger(out);
  PrintWriter pw = new PrintWriter(new OutputStreamWriter(bos, StandardCharsets.UTF_8));

  XMLEncoder beanEncoder = new XMLEncoder(bos);
  beanEncoder.setExceptionListener(new ExceptionListener() {
    public void exceptionThrown(Exception exception) {
      System.out.println("XMLStore.save() got Exception: abort saving the preferences!");
      exception.printStackTrace();
      outputExceptionMessage = exception.getMessage();
    }
  });

  pw.printf("<?xml version='1.0' encoding='UTF-8'?>%n");
  pw.printf("<preferences EXTERNAL_XML_VERSION='1.0'>%n");
  if (!rootPrefs.isUserNode())
    pw.printf("  <root type='system'>%n");
  else
    pw.printf("  <root type='user'>%n");

  Indent indent = new Indent(2);
  indent.incr();
  writeXmlNode(bos, pw, rootPrefs, beanEncoder, indent);
  if (outputExceptionMessage != null)
    throw new IOException(outputExceptionMessage);

  pw.printf("  </root>%n");
  pw.printf("</preferences>%n");
  pw.flush();
}
 
源代码8 项目: TencentKona-8   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码9 项目: jdk8u60   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码10 项目: openjdk-jdk8u   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码12 项目: openjdk-jdk9   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码13 项目: jdk8u-jdk   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码14 项目: hottub   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码15 项目: openjdk-8-source   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码16 项目: openjdk-8   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码17 项目: jdk8u_jdk   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码18 项目: jdk8u-jdk   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码19 项目: jdk8u-dev-jdk   文件: Test4676532.java
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
源代码20 项目: logbook-kai   文件: JarBasedPlugin.java
public static JarBasedPlugin toJarBasedPlugin(Path p, ExceptionListener listener) {
    try {
        return new JarBasedPlugin(p);
    } catch (IOException e) {
        listener.exceptionThrown(e);
        return null;
    }
}
 
源代码21 项目: siddhi   文件: StreamHandler.java
public StreamHandler(List<StreamJunction.Receiver> receivers, int batchSize,
                     String streamName, String siddhiAppName, StreamJunction faultStreamJunction,
                     StreamJunction.OnErrorAction onErrorAction, ExceptionListener exceptionListener) {
    this.receivers = receivers;
    this.batchSize = batchSize;
    this.streamName = streamName;
    this.siddhiAppName = siddhiAppName;
    this.faultStreamJunction = faultStreamJunction;
    this.onErrorAction = onErrorAction;
    this.exceptionListener = exceptionListener;
}
 
源代码22 项目: spiracle   文件: XSSviaXMLDeserialization.java
private static void serializeToXML (User settings, String path) throws IOException
{
    FileOutputStream fos = new FileOutputStream(path);
    XMLEncoder encoder = new XMLEncoder(fos);
    encoder.setExceptionListener(new ExceptionListener() {
            public void exceptionThrown(Exception e) {
                System.out.println("Exception! :"+e.toString());
            }
    });
    encoder.writeObject(settings);
    encoder.close();
    fos.close();
}
 
源代码23 项目: siddhi   文件: SiddhiAppRuntimeImpl.java
public void handleRuntimeExceptionWith(ExceptionListener exceptionListener) {
    siddhiAppContext.setRuntimeExceptionListener(exceptionListener);
}
 
源代码24 项目: siddhi   文件: SiddhiAppContext.java
public ExceptionListener getRuntimeExceptionListener() {
    return runtimeExceptionListener;
}
 
源代码25 项目: siddhi   文件: SiddhiAppContext.java
public void setRuntimeExceptionListener(ExceptionListener runtimeExceptionListener) {
    this.runtimeExceptionListener = runtimeExceptionListener;
}
 
源代码26 项目: dragonwell8_jdk   文件: DocumentHandler.java
/**
 * Returns the exception listener for parsing.
 * The exception listener is notified
 * when handler catches recoverable exceptions.
 * If the exception listener has not been explicitly set
 * then default exception listener is returned.
 *
 * @return the exception listener for parsing
 */
public ExceptionListener getExceptionListener() {
    return this.listener;
}
 
源代码27 项目: dragonwell8_jdk   文件: DocumentHandler.java
/**
 * Sets the exception listener for parsing.
 * The exception listener is notified
 * when handler catches recoverable exceptions.
 *
 * @param listener  the exception listener for parsing
 */
public void setExceptionListener(ExceptionListener listener) {
    this.listener = listener;
}
 
源代码28 项目: TencentKona-8   文件: DocumentHandler.java
/**
 * Returns the exception listener for parsing.
 * The exception listener is notified
 * when handler catches recoverable exceptions.
 * If the exception listener has not been explicitly set
 * then default exception listener is returned.
 *
 * @return the exception listener for parsing
 */
public ExceptionListener getExceptionListener() {
    return this.listener;
}
 
源代码29 项目: TencentKona-8   文件: DocumentHandler.java
/**
 * Sets the exception listener for parsing.
 * The exception listener is notified
 * when handler catches recoverable exceptions.
 *
 * @param listener  the exception listener for parsing
 */
public void setExceptionListener(ExceptionListener listener) {
    this.listener = listener;
}
 
源代码30 项目: jdk8u60   文件: DocumentHandler.java
/**
 * Returns the exception listener for parsing.
 * The exception listener is notified
 * when handler catches recoverable exceptions.
 * If the exception listener has not been explicitly set
 * then default exception listener is returned.
 *
 * @return the exception listener for parsing
 */
public ExceptionListener getExceptionListener() {
    return this.listener;
}
 
 类所在包
 同包方法