Refine search
packageFile = new File(System.getProperty("java.io.tmpdir") + File.separator + pkg.getName()+".pkg"); packageFile.deleteOnExit(); FileOutputStream out = new FileOutputStream(packageFile); try { DroolsStreamUtils.streamOut(out, pkg); } finally { out.close();
private static void compileChangeSet(String changeSet, String outputDir) { Long start=System.currentTimeMillis(); KnowledgeAgent kAgent = KnowledgeAgentFactory.newKnowledgeAgent( "CompilerAgent" ); kAgent.applyChangeSet(ResourceFactory.newFileResource(changeSet)); Collection<KnowledgePackage> kPackages = kAgent.getKnowledgeBase().getKnowledgePackages(); for (KnowledgePackage kPackage : kPackages) { String packageName = kPackage.getName(); try { String fileName=outputDir+"/"+packageName+".pkg"; DroolsStreamUtils.streamOut(new FileOutputStream(fileName), kPackage); System.out.println("File '"+fileName+"' was created."); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } System.out.format("Compilation time: %,dms\n", System.currentTimeMillis() - start); } }
@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 method reads the contents from the given input stream and returns the object. It is expected that * the contents in the given stream was not compressed, and it was written by the corresponding * streamOut methods of this class. * @param in * @return * @throws IOException * @throws ClassNotFoundException */ public static Object streamIn(InputStream in) throws IOException, ClassNotFoundException { return streamIn(in, null, false); }
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); (GroupElement[]) DroolsStreamUtils.streamIn( new FileInputStream(testFile));
/** * 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); }
/** * This method reads the contents from the given byte array and returns the object. It is expected that * the contents in the given buffer was not compressed, and the content stream was written by the corresponding * streamOut methods of this class. * @param bytes * @return * @throws IOException * @throws ClassNotFoundException */ public static Object streamIn(byte[] bytes) throws IOException, ClassNotFoundException { return streamIn(bytes, null); }
getLog().info("Writing KBase: " + kbase); File file = new File(outputFolder, kbase.replace('.', '_').toLowerCase()); FileOutputStream out = new FileOutputStream(file); DroolsStreamUtils.streamOut(out, kb.getKiePackages()); out.close();
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 ) { } } } }
DroolsStreamUtils.streamOut(new FileOutputStream(testFile), result); final GroupElement[] correctResultRoot = (GroupElement[]) DroolsStreamUtils.streamIn(new FileInputStream(testFile));
@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() ); }
/** * This method reads the contents from the given input stream and returns the object. It is expected that * the contents in the given stream was not compressed, and it was written by the corresponding * streamOut methods of this class. * @param in * @param classLoader * @return * @throws IOException * @throws ClassNotFoundException */ public static Object streamIn(InputStream in, ClassLoader classLoader) throws IOException, ClassNotFoundException { return streamIn(in, classLoader, false); }
getLog().info("Writing KBase: " + kbase); File file = new File(outputFolder, kbase.replace('.', '_').toLowerCase()); FileOutputStream out = new FileOutputStream(file); DroolsStreamUtils.streamOut(out, kb.getKiePackages()); out.close();
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) { } } } }
@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 ); }
@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() ); }