public void writeKnowledgePackage(Collection<KiePackage> pkgs, String filePath) { FileOutputStream fileOutStream = null; DroolsObjectOutputStream out = null; try { fileOutStream = new FileOutputStream(filePath); out = new DroolsObjectOutputStream(fileOutStream); out.writeObject(pkgs); out.flush(); } catch(Exception ex){ // TODO }finally { try{ if(out != null) out.close(); if(fileOutStream != null) fileOutStream.close(); }catch(Exception e){} } } }
DroolsObjectOutputStream out = new DroolsObjectOutputStream(byteOutStream);) { out.writeObject(knowledgePackages); out.flush(); pkgBin = byteOutStream.toByteArray();
private static byte[] serialize(Object obj) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutput out = new DroolsObjectOutputStream(bytes); out.writeObject(obj); out.flush(); out.close(); return bytes.toByteArray(); }
DroolsObjectOutputStream out = new DroolsObjectOutputStream(byteOutStream);) { out.writeObject(knowledgePackages); out.flush(); pkgBin = byteOutStream.toByteArray();
private static void bigBlobCompile() throws DroolsParserException, IOException, Exception { StringBuilder buf = new StringBuilder(); buf.append(getHeader()); for (int i = 0; i < 1; i++) { String name = "x" + i; int status = i; String r = getTemplate1(name, status); buf.append(r); } KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newByteArrayResource(buf.toString().getBytes()), ResourceType.DRL ); InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addPackages(kbuilder.getKnowledgePackages()); File f = new File("foo.rulebase"); if (f.exists()) f.delete(); ObjectOutput out = new DroolsObjectOutputStream(new FileOutputStream(f)); out.writeObject(kbase); out.flush(); out.close(); ObjectInputStream in = new DroolsObjectInputStream(new FileInputStream(f)); KieBase rb_ = (KieBase) in.readObject(); } public static String getHeader() {
public void saveSession( FileOutputStream output, KieSession ksession ) throws IOException { DroolsObjectOutputStream droolsOut = new DroolsObjectOutputStream( output ); droolsOut.writeObject( ksession.getKieBase() ); Marshaller mas = createMarshaller( ksession.getKieBase() ); mas.marshall( droolsOut, ksession ); droolsOut.flush(); droolsOut.close(); }
ObjectOutputStream out = new DroolsObjectOutputStream( baos ); out.writeObject( bob ); out.writeObject( kbase );
@Test public void testJBRULES_1946_3() { KieBase kbase = loadKnowledgeBase("../Sample.drl" ); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DroolsObjectOutputStream oos = new DroolsObjectOutputStream( baos ); oos.writeObject( kbase ); oos.flush(); oos.close(); baos.flush(); baos.close(); byte[] serializedKb = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream( serializedKb ); ObjectInputStream ois = new ObjectInputStream( bais ); KieBase kb2 = (KieBase) ois.readObject(); fail( "Should have raised an IllegalArgumentException since the kbase was serialized with a Drools Stream but deserialized with a regular stream" ); } catch ( IllegalArgumentException ode ) { // success } catch ( Exception e ) { e.printStackTrace(); fail( "Unexpected exception: " + e.getMessage() ); } }
ObjectOutputStream out = new DroolsObjectOutputStream( baos ); out.writeObject( knowledgePackagesCombined ); out.flush();
@Test public void testJBRULES_1946_2() { KieBase kbase = loadKnowledgeBase("../Sample.drl" ); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DroolsObjectOutputStream oos = new DroolsObjectOutputStream( baos ); oos.writeObject( kbase ); oos.flush(); oos.close(); baos.flush(); baos.close(); byte[] serializedKb = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream( serializedKb ); DroolsObjectInputStream ois = new DroolsObjectInputStream( bais ); KieBase kb2 = (KieBase) ois.readObject(); } catch ( OptionalDataException ode ) { ode.printStackTrace(); fail( "EOF? " + ode.eof ); } catch ( Exception e ) { e.printStackTrace(); fail( "Unexpected exception: " + e.getMessage() ); } }
ObjectOutputStream out = new DroolsObjectOutputStream( baos ); out.writeObject( kbase ); marshaller.marshall( out,
DroolsObjectOutputStream oos = new DroolsObjectOutputStream( baos ); oos.writeObject( kb1 ); oos.flush(); oos.close(); baos.flush(); baos.close();
ObjectOutputStream out = new DroolsObjectOutputStream( baos ); out.writeObject( knowledgePackagesCombined ); out.flush();
@Test public void testJBRULES_1946_3() { KnowledgeBase kbase = loadKnowledgeBase("../Sample.drl" ); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DroolsObjectOutputStream oos = new DroolsObjectOutputStream( baos ); oos.writeObject( kbase ); oos.flush(); oos.close(); baos.flush(); baos.close(); byte[] serializedKb = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream( serializedKb ); ObjectInputStream ois = new ObjectInputStream( bais ); KnowledgeBase kb2 = (KnowledgeBase) ois.readObject(); fail( "Should have raised an IllegalArgumentException since the kbase was serialized with a Drools Stream but deserialized with a regular stream" ); } catch ( IllegalArgumentException ode ) { // success } catch ( Exception e ) { e.printStackTrace(); fail( "Unexpected exception: " + e.getMessage() ); } }
ObjectOutputStream out = new DroolsObjectOutputStream( baos ); out.writeObject( bob ); out.writeObject( kbase );
@Test public void testJBRULES_1946_2() { KnowledgeBase kbase = loadKnowledgeBase("../Sample.drl" ); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DroolsObjectOutputStream oos = new DroolsObjectOutputStream( baos ); oos.writeObject( kbase ); oos.flush(); oos.close(); baos.flush(); baos.close(); byte[] serializedKb = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream( serializedKb ); DroolsObjectInputStream ois = new DroolsObjectInputStream( bais ); KnowledgeBase kb2 = (KnowledgeBase) ois.readObject(); } catch ( OptionalDataException ode ) { ode.printStackTrace(); fail( "EOF? " + ode.eof ); } catch ( Exception e ) { e.printStackTrace(); fail( "Unexpected exception: " + e.getMessage() ); } }
ObjectOutputStream out = new DroolsObjectOutputStream( baos ); out.writeObject( kbase ); marshaller.marshall( out,