/**
* Handles the write serialization of the Package. Patterns in Rules may reference generated data which cannot be serialized by default methods.
* The Package uses PackageCompilationData to hold a reference to the generated bytecode. The generated bytecode must be restored before any Rules.
*/
public void writeExternal(final ObjectOutput stream) throws IOException {
DroolsObjectOutputStream droolsStream;
boolean isDrools = stream instanceof DroolsObjectOutputStream;
ByteArrayOutputStream bytes = null;
stream.writeBoolean( isDrools );
if ( isDrools ) {
droolsStream = (DroolsObjectOutputStream) stream;
} else {
bytes = new ByteArrayOutputStream();
droolsStream = new DroolsObjectOutputStream( bytes );
}
super.writeExternal( droolsStream );
droolsStream.writeObject( this.reteooBuilder );
droolsStream.writeObject( this.rete );
if ( !isDrools ) {
droolsStream.flush();
droolsStream.close();
bytes.close();
stream.writeObject( bytes.toByteArray() );
}
}