use of java.io.ObjectOutput in project drools by kiegroup.
the class JavaDialectRuntimeData method writeExternal.
/**
* Handles the write serialization of the PackageCompilationData. Patterns in Rules may reference generated data which cannot be serialized by
* default methods. The PackageCompilationData holds a reference to the generated bytecode. The generated bytecode must be restored before any Rules.
*/
public void writeExternal(ObjectOutput stream) throws IOException {
KeyStoreHelper helper = new KeyStoreHelper();
stream.writeBoolean(helper.isSigned());
if (helper.isSigned()) {
stream.writeObject(helper.getPvtKeyAlias());
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeInt(this.store.size());
for (Entry<String, byte[]> entry : this.store.entrySet()) {
out.writeObject(entry.getKey());
out.writeObject(entry.getValue());
}
out.flush();
out.close();
byte[] buff = bos.toByteArray();
stream.writeObject(buff);
if (helper.isSigned()) {
sign(stream, helper, buff);
}
stream.writeInt(this.invokerLookups.size());
for (Entry<String, Wireable> entry : this.invokerLookups.entrySet()) {
stream.writeObject(entry.getKey());
stream.writeObject(entry.getValue());
}
stream.writeInt(this.classLookups.size());
for (Entry<String, byte[]> entry : this.classLookups.entrySet()) {
stream.writeObject(entry.getKey());
stream.writeObject(entry.getValue());
}
}
use of java.io.ObjectOutput in project drools by kiegroup.
the class PackageDescrTest method testSerialization.
@Test
public void testSerialization() {
PackageDescrBuilder builder = DescrFactory.newPackage().name("foo");
String className = Person.class.getName();
builder.newImport().target(className).end();
PackageDescr descr = builder.getDescr();
ImportDescr importDescr = new ImportDescr(className);
ImportDescr badImportDescr = new ImportDescr(null);
assertTrue(descr.getImports().contains(importDescr));
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(baos);
descr.writeExternal(out);
ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
PackageDescr newDescr = new PackageDescr();
newDescr.readExternal(in);
assertFalse(newDescr.getImports().contains(badImportDescr));
assertTrue(newDescr.getImports().contains(importDescr));
} catch (IOException ioe) {
fail(ioe.getMessage());
} catch (ClassNotFoundException cnfe) {
fail(cnfe.getMessage());
}
}
Aggregations