this approach works fine, I use it this way (import / export)
public Collection<KnowledgePackage> importPackages(InputStream input) {
Collection<KnowledgePackage> pkgs = Collections.emptyList();
try {
if (input == null || input.available() <= 0)
return pkgs;
ObjectInputStream ois = new ObjectInputStream(input);
pkgs = (Collection<KnowledgePackage>) ois.readObject();
return pkgs;
} catch (IOException e) {
LOG.warn("IOException during package import : " + e.getMessage());
} catch (ClassNotFoundException e) {
LOG.warn("Class saved in the stream does not exists : " +
e.getMessage());
}
return pkgs;
}
boolean exportPackages(Collection<KnowledgePackage> pkgs, OutputStream
output) {
if (pkgs != null && pkgs.size() > 0 && output != null){
try {
ObjectOutputStream oos = new ObjectOutputStream(output);
oos.writeObject(pkgs);
oos.close();
output.close();
return true;
} catch (IOException e) {
LOG.warn("Error exporting rules package : " + e.getMessage());
}
}
return false;
}
tune it as you want, hope it helps.
Erik Clairiot
On Tue, 28 Jul 2009 06:50:21 -0700 (PDT), Olaf Raether <o.raether(a)epro.de>
wrote:
now i found out, that my problems are in relation to my serialized
KnowledgePackages.
When i use the following code and load the drl files everything is fine !
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(rules[i] +
".drl")),
ResourceType.DRL);
But this takes too long, when i used it the first time - so i want to use
serialized
KnowledgePackages again.
So my question is: What is the right way to serialize/deserialize
KnowledgePackages ?
As you have seen in my posts i used standard readObject/writeObject
methods.
Is this the right approach ?
Thanks.