@SuppressWarnings("unchecked") public static <T> T serializeObject(T obj, ClassLoader classLoader) throws IOException, ClassNotFoundException { return (T) DroolsStreamUtils.streamIn( DroolsStreamUtils.streamOut( obj ), classLoader ); }
InternalKnowledgePackage pkg2 = (InternalKnowledgePackage) DroolsStreamUtils.streamIn( DroolsStreamUtils.streamOut( pkg ) ); assertNotNull( pkg2 );
@Test public void testRuleFlow() throws Exception { InputStream in = this.getClass().getResourceAsStream( "/org/jbpm/integrationtests/ruleflow.rfm" ); assertNotNull( in ); builder.addPackage( new PackageDescr( "com.sample" ) ); builder.addRuleFlow( new InputStreamReader( in ) ); InternalKnowledgePackage pkg = builder.getPackage("com.sample"); assertNotNull( pkg ); Map<String, Process> flows = pkg.getRuleFlows(); assertNotNull( flows ); assertEquals( 1, flows.size() ); assertTrue( flows.containsKey( "0" ) ); Process p = (Process) flows.get( "0" ); assertTrue( p instanceof WorkflowProcessImpl ); //now serialization InternalKnowledgePackage pkg2 = (InternalKnowledgePackage) DroolsStreamUtils.streamIn( DroolsStreamUtils.streamOut( pkg ) ); assertNotNull( pkg2 ); flows = pkg2.getRuleFlows(); assertNotNull( flows ); assertEquals( 1, flows.size() ); assertTrue( flows.containsKey( "0" ) ); p = (Process) flows.get( "0" ); assertTrue( p instanceof WorkflowProcessImpl ); }
FileOutputStream out = new FileOutputStream(packageFile); try { DroolsStreamUtils.streamOut(out, pkg); } finally { out.close();
@SuppressWarnings("unchecked") public static <T> T serializeObject(final T obj, final ClassLoader classLoader) throws IOException, ClassNotFoundException { return (T) DroolsStreamUtils.streamIn(DroolsStreamUtils.streamOut(obj), classLoader); }
public static <T> T serializeObject(T obj, ClassLoader classLoader) throws IOException, ClassNotFoundException { return (T)DroolsStreamUtils.streamIn(DroolsStreamUtils.streamOut(obj), classLoader); } }
@Test public void testFileIO() throws Exception { FooBar fooBar1 = new FooBar(); ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); new ObjectOutputStream(byteArrayOut).writeObject(fooBar1); ByteArrayInputStream byteArrayIn = new ByteArrayInputStream(byteArrayOut.toByteArray()); FooBar fooBar2 = (FooBar) new ObjectInputStream(byteArrayIn).readObject(); final File testFile = new File("target/test/DroolsObjectIOTest_testFileIO.dat"); testFile.getParentFile().mkdirs(); GroupElement testGroupElement = new GroupElement(); DroolsStreamUtils.streamOut(new FileOutputStream(testFile), testGroupElement); InputStream fis = new FileInputStream(testFile); GroupElement streamedGroupElement = (GroupElement) DroolsStreamUtils.streamIn(new FileInputStream(testFile)); assertEquals(streamedGroupElement, testGroupElement); }
/** * This method would stream out the given object to the given output stream uncompressed. * The output contents could only be read by the corresponding "streamIn" method of this class. * @param out * @param object * @throws IOException */ public static void streamOut(OutputStream out, Object object) throws IOException { streamOut(out, object, false); }
/** * This routine would stream out the give object uncompressed and store the streamed contents in * the return byte array. The output contents could only be read by the corresponding "streamIn" * method of this class. * @param object * @return * @throws IOException */ public static byte[] streamOut(Object object) throws IOException { return streamOut(object, false); }
out = DroolsStreamUtils.streamOut( kpkgs );
@Test public void testAddKPackageSingle() throws Exception { String rule = "package org.drools.compiler.test\n" + "import org.drools.compiler.StockTick\n" + "rule R1 when\n" + " StockTick()\n" + "then\n" + "end\n"; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newByteArrayResource( rule.getBytes() ), ResourceType.DRL ); assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() ); Collection<KiePackage> kpkgs = kbuilder.getKnowledgePackages(); assertEquals( 2, kpkgs.size() ); KiePackage kpkg = kpkgs.iterator().next(); byte[] skpkg = DroolsStreamUtils.streamOut( kpkg ); kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newByteArrayResource( skpkg ), ResourceType.PKG ); assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() ); kpkgs = kbuilder.getKnowledgePackages(); assertEquals( 1, kpkgs.size() ); kpkg = kpkgs.iterator().next(); assertEquals( 1, kpkg.getRules().size() ); }
byte[] out = DroolsStreamUtils.streamOut( kpkgs );
@Test public void testAddKPackageCollection() throws Exception { String rule = "package org.drools.compiler.test\n" + "import org.drools.compiler.StockTick\n" + "declare StockTick @role(event) end\n" + "rule R1 when\n" + " StockTick()\n" + "then\n" + "end\n"; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newByteArrayResource( rule.getBytes() ), ResourceType.DRL ); assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() ); Collection<KiePackage> kpkgs = kbuilder.getKnowledgePackages(); assertEquals( 2, kpkgs.size() ); byte[] skpkg = DroolsStreamUtils.streamOut( kpkgs ); kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newByteArrayResource( skpkg ), ResourceType.PKG ); assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() ); kpkgs = kbuilder.getKnowledgePackages(); assertEquals( 2, kpkgs.size() ); }
/** * This routine would stream out the give object, uncompressed or compressed depending on the given flag, * and store the streamed contents in the return byte array. The output contents could only be read by * the corresponding "streamIn" method of this class. * @param object * @param compressed * @return * @throws IOException */ public static byte[] streamOut(Object object, boolean compressed) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); streamOut(bytes, object, compressed); bytes.flush(); bytes.close(); return bytes.toByteArray(); }
public static <T> T serializeObject(T obj, ClassLoader classLoader) throws IOException, ClassNotFoundException { return (T) DroolsStreamUtils.streamIn( DroolsStreamUtils.streamOut( obj ), classLoader ); }
public static void writePackage(KiePackage pkg, File dest) { dest.deleteOnExit(); OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(dest)); DroolsStreamUtils.streamOut(out, pkg); } catch (Exception e) { throw new RuntimeException(e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { } } } }
public static void writePackage(Package pkg, File dest) { dest.deleteOnExit(); OutputStream out = null; try { out = new BufferedOutputStream( new FileOutputStream( dest ) ); DroolsStreamUtils.streamOut( out, pkg ); } catch ( Exception e ) { throw new RuntimeException( e ); } finally { if ( out != null ) { try { out.close(); } catch ( IOException e ) { } } } }
public static void writePackage(KiePackage pkg, File dest) { dest.deleteOnExit(); OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(dest)); DroolsStreamUtils.streamOut(out, pkg); } catch (Exception e) { throw new RuntimeException(e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { } } } }
DroolsStreamUtils.streamOut(new FileOutputStream(testFile), ands);
DroolsStreamUtils.streamOut(new FileOutputStream(testFile), result); final GroupElement[] correctResultRoot = (GroupElement[]) DroolsStreamUtils.streamIn(new FileInputStream(testFile));