Search in sources :

Example 6 with XMLEncoder

use of java.beans.XMLEncoder in project SQLWindowing by hbutani.

the class SerializationUtils method serialize.

public static void serialize(OutputStream out, Object o) {
    XMLEncoder e = new XMLEncoder(out);
    e.setExceptionListener(new EL());
    SerializationUtils.addPersistenceDelegates(e);
    e.writeObject(o);
    e.close();
}
Also used : XMLEncoder(java.beans.XMLEncoder)

Example 7 with XMLEncoder

use of java.beans.XMLEncoder in project jdk8u_jdk by JetBrains.

the class Test4625418 method test.

private void test(String string) {
    try {
        File file = new File("4625418." + this.encoding + ".xml");
        FileOutputStream output = new FileOutputStream(file);
        XMLEncoder encoder = new XMLEncoder(output, this.encoding, true, 0);
        encoder.setExceptionListener(this);
        encoder.writeObject(string);
        encoder.close();
        FileInputStream input = new FileInputStream(file);
        XMLDecoder decoder = new XMLDecoder(input);
        decoder.setExceptionListener(this);
        Object object = decoder.readObject();
        decoder.close();
        if (!string.equals(object))
            throw new Error(this.encoding + " - can't read properly");
        file.delete();
    } catch (FileNotFoundException exception) {
        throw new Error(this.encoding + " - file not found", exception);
    } catch (IllegalCharsetNameException exception) {
        throw new Error(this.encoding + " - illegal charset name", exception);
    } catch (UnsupportedCharsetException exception) {
        throw new Error(this.encoding + " - unsupported charset", exception);
    } catch (UnsupportedOperationException exception) {
        throw new Error(this.encoding + " - unsupported encoder", exception);
    }
}
Also used : IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) XMLEncoder(java.beans.XMLEncoder) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) FileOutputStream(java.io.FileOutputStream) XMLDecoder(java.beans.XMLDecoder) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 8 with XMLEncoder

use of java.beans.XMLEncoder in project jdk8u_jdk by JetBrains.

the class AbstractTest method test.

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);
}
Also used : XMLEncoder(java.beans.XMLEncoder) DefaultPersistenceDelegate(java.beans.DefaultPersistenceDelegate) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLDecoder(java.beans.XMLDecoder) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 9 with XMLEncoder

use of java.beans.XMLEncoder in project jdk8u_jdk by JetBrains.

the class Test4968523 method test.

private static void test(Class<?> type, PersistenceDelegate pd) {
    Encoder encoder1 = new Encoder();
    Encoder encoder2 = new XMLEncoder(System.out);
    PersistenceDelegate pd1 = encoder1.getPersistenceDelegate(type);
    PersistenceDelegate pd2 = encoder2.getPersistenceDelegate(type);
    encoder1.setPersistenceDelegate(type, pd);
    if (pd1 == encoder1.getPersistenceDelegate(type))
        throw new Error("first persistence delegate is not changed");
    if (pd2 != encoder2.getPersistenceDelegate(type))
        throw new Error("second persistence delegate is changed");
}
Also used : XMLEncoder(java.beans.XMLEncoder) Encoder(java.beans.Encoder) XMLEncoder(java.beans.XMLEncoder) DefaultPersistenceDelegate(java.beans.DefaultPersistenceDelegate) PersistenceDelegate(java.beans.PersistenceDelegate)

Example 10 with XMLEncoder

use of java.beans.XMLEncoder in project jdk8u_jdk by JetBrains.

the class Test5023559 method initialize.

protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(Parent.class, new PersistenceDelegate() {

        protected Expression instantiate(Object old, Encoder out) {
            Parent parent = (Parent) old;
            return new Expression(old, parent.getParent(), "create", new Object[] {});
        }
    });
    encoder.setPersistenceDelegate(Child.class, new PersistenceDelegate() {

        protected Expression instantiate(Object old, Encoder out) {
            Child child = (Child) old;
            return new Expression(old, child.getParent(), "create", new Object[] {});
        }
    });
}
Also used : Expression(java.beans.Expression) Encoder(java.beans.Encoder) XMLEncoder(java.beans.XMLEncoder) PersistenceDelegate(java.beans.PersistenceDelegate)

Aggregations

XMLEncoder (java.beans.XMLEncoder)22 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 XMLDecoder (java.beans.XMLDecoder)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 LinkedList (java.util.LinkedList)5 Test (org.junit.Test)5 ExceptionListener (java.beans.ExceptionListener)4 PersistenceDelegate (java.beans.PersistenceDelegate)4 BufferedOutputStream (java.io.BufferedOutputStream)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 AssertionFailedError (junit.framework.AssertionFailedError)4 DefaultPersistenceDelegate (java.beans.DefaultPersistenceDelegate)3 Encoder (java.beans.Encoder)3 IOException (java.io.IOException)3 Expression (java.beans.Expression)2 BufferedInputStream (java.io.BufferedInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 MapNode (aimax.osm.data.entities.MapNode)1