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();
}
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);
}
}
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);
}
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");
}
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[] {});
}
});
}
Aggregations