Java Code Examples for java.beans.XMLEncoder#setExceptionListener()
The following examples show how to use
java.beans.XMLEncoder#setExceptionListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestObjectEncode.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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(); }
Example 2
Source File: Test4880633.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void run() { // run thread a few time // object stays the same but NullPointerException appears randomly // on dual proccessor a lock is generated for (int i = 0; i < THREAD_LENGTH; i++) { // create XMLEncoder to ByteArrayOutputStream // this is to exclude file locking problems XMLEncoder encoder = new XMLEncoder(new ByteArrayOutputStream()); encoder.setExceptionListener(this); // write the object // will see randomly null pointer exceptions // a bug as object is same through different encode phases encoder.writeObject(this.object); //close encoder encoder.close(); } System.out.println(Thread.currentThread().getName() + " is finished"); }
Example 3
Source File: Test4880633.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public void run() { // run thread a few time // object stays the same but NullPointerException appears randomly // on dual proccessor a lock is generated for (int i = 0; i < THREAD_LENGTH; i++) { // create XMLEncoder to ByteArrayOutputStream // this is to exclude file locking problems XMLEncoder encoder = new XMLEncoder(new ByteArrayOutputStream()); encoder.setExceptionListener(this); // write the object // will see randomly null pointer exceptions // a bug as object is same through different encode phases encoder.writeObject(this.object); //close encoder encoder.close(); } System.out.println(Thread.currentThread().getName() + " is finished"); }
Example 4
Source File: Test4880633.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public void run() { // run thread a few time // object stays the same but NullPointerException appears randomly // on dual proccessor a lock is generated for (int i = 0; i < THREAD_LENGTH; i++) { // create XMLEncoder to ByteArrayOutputStream // this is to exclude file locking problems XMLEncoder encoder = new XMLEncoder(new ByteArrayOutputStream()); encoder.setExceptionListener(this); // write the object // will see randomly null pointer exceptions // a bug as object is same through different encode phases encoder.writeObject(this.object); //close encoder encoder.close(); } System.out.println(Thread.currentThread().getName() + " is finished"); }
Example 5
Source File: Test6329581.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private byte[] encode(String name) throws Exception { Object object = loadClass(name).newInstance(); validate(object); ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(out); encoder.setExceptionListener(this); encoder.writeObject(object); encoder.close(); return out.toByteArray(); }
Example 6
Source File: AbstractTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private byte[] writeObject(Object object) { ByteArrayOutputStream output = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(output); encoder.setExceptionListener(this); initialize(encoder); encoder.writeObject(object); encoder.close(); return output.toByteArray(); }
Example 7
Source File: Test6329581.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private byte[] encode(String name) throws Exception { Object object = loadClass(name).newInstance(); validate(object); ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(out); encoder.setExceptionListener(this); encoder.writeObject(object); encoder.close(); return out.toByteArray(); }
Example 8
Source File: XMLStore.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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(); }
Example 9
Source File: AbstractTest.java From hottub with GNU General Public License v2.0 | 5 votes |
private byte[] writeObject(Object object) { ByteArrayOutputStream output = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(output); encoder.setExceptionListener(this); initialize(encoder); encoder.writeObject(object); encoder.close(); return output.toByteArray(); }
Example 10
Source File: AbstractTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private byte[] writeObject(Object object) { ByteArrayOutputStream output = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(output); encoder.setExceptionListener(this); initialize(encoder); encoder.writeObject(object); encoder.close(); return output.toByteArray(); }
Example 11
Source File: Test6329581.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private byte[] encode(String name) throws Exception { Object object = loadClass(name).newInstance(); validate(object); ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(out); encoder.setExceptionListener(this); encoder.writeObject(object); encoder.close(); return out.toByteArray(); }
Example 12
Source File: Test6329581.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private byte[] encode(String name) throws Exception { Object object = loadClass(name).newInstance(); validate(object); ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(out); encoder.setExceptionListener(this); encoder.writeObject(object); encoder.close(); return out.toByteArray(); }
Example 13
Source File: AbstractTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private byte[] writeObject(Object object) { ByteArrayOutputStream output = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(output); encoder.setExceptionListener(this); initialize(encoder); encoder.writeObject(object); encoder.close(); return output.toByteArray(); }
Example 14
Source File: javax_swing_DefaultCellEditor.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Override protected void initialize(XMLEncoder encoder) { encoder.setExceptionListener(null); // TODO: ignore non-public listener because of 4808251 }
Example 15
Source File: javax_swing_DefaultCellEditor.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override protected void initialize(XMLEncoder encoder) { encoder.setExceptionListener(null); // TODO: ignore non-public listener because of 4808251 }
Example 16
Source File: javax_swing_DefaultCellEditor.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override protected void initialize(XMLEncoder encoder) { encoder.setExceptionListener(null); // TODO: ignore non-public listener because of 4808251 }
Example 17
Source File: javax_swing_DefaultCellEditor.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override protected void initialize(XMLEncoder encoder) { encoder.setExceptionListener(null); // TODO: ignore non-public listener because of 4808251 }
Example 18
Source File: javax_swing_DefaultCellEditor.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override protected void initialize(XMLEncoder encoder) { encoder.setExceptionListener(null); // TODO: ignore non-public listener because of 4808251 }
Example 19
Source File: javax_swing_DefaultCellEditor.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Override protected void initialize(XMLEncoder encoder) { encoder.setExceptionListener(null); // TODO: ignore non-public listener because of 4808251 }
Example 20
Source File: javax_swing_DefaultCellEditor.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Override protected void initialize(XMLEncoder encoder) { encoder.setExceptionListener(null); // TODO: ignore non-public listener because of 4808251 }