Java Code Examples for java.beans.XMLEncoder#writeObject()
The following examples show how to use
java.beans.XMLEncoder#writeObject() .
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: Test4880633.java From openjdk-jdk9 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 2
Source File: AbstractTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
static void test(AbstractTest object) { ByteArrayOutputStream output = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(output); encoder.setPersistenceDelegate( object.getClass(), new DefaultPersistenceDelegate(new String[] {"value"})); encoder.writeObject(object); encoder.close(); System.out.print(output); ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray()); XMLDecoder decoder = new XMLDecoder(input); AbstractTest result = (AbstractTest) decoder.readObject(); decoder.close(); if (object.getValue() != result.getValue()) throw new Error("Should be " + object); }
Example 3
Source File: MainFrame.java From procamcalib with GNU General Public License v2.0 | 6 votes |
void saveSettings(File file) throws IOException { settingsFile = file; if (settingsFile == null) { setTitle(PRO_CAM_CALIB); } else { setTitle(settingsFile.getName() + " - ProCamCalib"); } XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(settingsFile))); encoder.writeObject(cameraSettings); encoder.writeObject(projectorSettings); encoder.writeObject(markerSettings); encoder.writeObject(markerDetectorSettings); encoder.writeObject(geometricCalibratorSettings); encoder.writeObject(colorCalibratorSettings); if (calibrationFile != null) { encoder.writeObject(calibrationFile.getAbsolutePath()); } encoder.close(); }
Example 4
Source File: AbstractTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
static void test(AbstractTest object) { ByteArrayOutputStream output = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(output); encoder.setPersistenceDelegate( object.getClass(), new DefaultPersistenceDelegate(new String[] {"value"})); encoder.writeObject(object); encoder.close(); System.out.print(output); ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray()); XMLDecoder decoder = new XMLDecoder(input); AbstractTest result = (AbstractTest) decoder.readObject(); decoder.close(); if (object.getValue() != result.getValue()) throw new Error("Should be " + object); }
Example 5
Source File: AbstractTest.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
static void test(AbstractTest object) { ByteArrayOutputStream output = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(output); encoder.setPersistenceDelegate( object.getClass(), new DefaultPersistenceDelegate(new String[] {"value"})); encoder.writeObject(object); encoder.close(); System.out.print(output); ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray()); XMLDecoder decoder = new XMLDecoder(input); AbstractTest result = (AbstractTest) decoder.readObject(); decoder.close(); if (object.getValue() != result.getValue()) throw new Error("Should be " + object); }
Example 6
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 7
Source File: Test4880633.java From jdk8u-jdk 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 8
Source File: UserManagerXMLPersist.java From BiglyBT with GNU General Public License v2.0 | 6 votes |
/** * This code abstracted because it relies on java.beans.* which is not always available * e.g. on Android */ @Override public void doSave( OutputStream out, Map usersMap ) { UserManagerConfig config = new UserManagerConfig(); List users = new ArrayList( usersMap.values() ); config.setUsers(users); XMLEncoder encoder = new XMLEncoder( new BufferedOutputStream( out ) ); encoder.writeObject(config); encoder.close(); }
Example 9
Source File: Test4822050.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(baos); encoder.writeObject(new JLabel("hello")); // NON-NLS: test message encoder.close(); byte[] buffer = baos.toByteArray(); for (int i = 0; i < THREADS; i++) start(buffer); }
Example 10
Source File: Test6329581.java From jdk8u-jdk 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 11
Source File: Test6329581.java From jdk8u-dev-jdk 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: RecentDocumentsManager.java From PyramidShader with GNU General Public License v3.0 | 5 votes |
protected void saveListOfRecentDocuments(LinkedList<RecentDocument> recentDocuments) { ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(out); for (RecentDocument doc : recentDocuments) encoder.writeObject(doc); encoder.close(); writeRecentDocs(out.toByteArray()); }
Example 13
Source File: LargeEntriesTest.java From Chronicle-Map with Apache License 2.0 | 5 votes |
private String generateValue(int entrySize) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder xml = new XMLEncoder(baos); Map<String, String> map2 = new HashMap<>(); Random rand = new Random(1); for (int i = 0; i < entrySize / 80; i++) map2.put("key-" + i, "value-" + rand.nextInt(1000)); xml.writeObject(map2); xml.close(); return baos.toString().substring(0, entrySize); }
Example 14
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 15
Source File: Test4822050.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(baos); encoder.writeObject(new JLabel("hello")); // NON-NLS: test message encoder.close(); byte[] buffer = baos.toByteArray(); for (int i = 0; i < THREADS; i++) start(buffer); }
Example 16
Source File: AbstractTest.java From openjdk-8-source 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 17
Source File: Test6329581.java From openjdk-jdk8u-backup 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 18
Source File: Test6329581.java From dragonwell8_jdk 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 19
Source File: GradebookArchive.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Serializes this gradebook archive into an xml document */ public String archive() { if(log.isDebugEnabled()) log.debug("GradebookArchive.archive() called"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(baos)); encoder.writeObject(this); encoder.flush(); String xml = baos.toString(); if(log.isDebugEnabled()) log.debug("GradebookArchive.archive() finished"); return xml; }
Example 20
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(); }