Java Code Examples for java.beans.XMLEncoder#close()

The following examples show how to use java.beans.XMLEncoder#close() . 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: AbstractTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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 2
Source File: AbstractTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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: Test4880633.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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 TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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: AbstractTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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: WebServicePersistenceManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void saveDescriptor(WebServiceDescriptor descriptor) throws IOException {
    XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(descriptor.getXmlDescriptor())));
    encoder.setExceptionListener(this);
    DefaultPersistenceDelegate delegate = new WebServiceDataPersistenceDelegate();
    encoder.setPersistenceDelegate(WSService.class, delegate);
    encoder.writeObject(descriptor);

    encoder.flush();
    encoder.close();
}
 
Example 7
Source File: AbstractTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: Test4822050.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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 9
Source File: AbstractTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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: Test6329581.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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: CacheTypeTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
private <T> T copyObjectViaXmlEncoder(T o) {
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  XMLEncoder enc = new XMLEncoder(bos);
  enc.writeObject(o);
  enc.close();
  ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
  XMLDecoder dec = new XMLDecoder(bin);
  Object o2 = dec.readObject();
  dec.close();
  assertTrue("no reference identity", o2 != o);
  assertEquals("same class", o.getClass(), o2.getClass());
  return (T) o2;
}
 
Example 12
Source File: Test.java    From native-obfuscator with GNU General Public License v3.0 5 votes vote down vote up
public static Character encodeDecode(Character character) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(out);
    encoder.writeObject(character);
    encoder.close();
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    return (Character)new XMLDecoder(in).readObject();

}
 
Example 13
Source File: Test6329581.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 14
Source File: AbstractTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 15
Source File: UpdateXmlSerializerImpl.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
/**
 * @see net.sourceforge.squirrel_sql.client.update.xmlbeans.UpdateXmlSerializer#write(net.sourceforge.squirrel_sql.client.update.xmlbeans.ChannelXmlBean, java.lang.String)
 */
public void write(ChannelXmlBean channelBean, String filename)
      throws FileNotFoundException {
   XMLEncoder os = getXmlEncoder(filename);
   os.writeObject(channelBean);
   os.close();
}
 
Example 16
Source File: Test6329581.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 17
Source File: Test4822050.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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 18
Source File: Test4822050.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 19
Source File: Test6329581.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 20
Source File: Test4822050.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}