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){} } } }
@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() ); } }
@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() ); } }
oos.flush(); oos.close(); baos.flush();
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(); }
DroolsObjectOutputStream out = new DroolsObjectOutputStream(byteOutStream);) { out.writeObject(knowledgePackages); out.flush(); pkgBin = byteOutStream.toByteArray();
DroolsObjectOutputStream out = new DroolsObjectOutputStream(byteOutStream);) { out.writeObject(knowledgePackages); out.flush(); pkgBin = byteOutStream.toByteArray();
@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() ); } }
@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() ); } }