@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 ); }
@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 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); }
/** * 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); }
/** * 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 * @param classLoader * @return * @throws IOException * @throws ClassNotFoundException */ public static Object streamIn(byte[] bytes, ClassLoader classLoader) throws IOException, ClassNotFoundException { return streamIn(bytes, classLoader, 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 * @param classLoader * @return * @throws IOException * @throws ClassNotFoundException */ public static Object streamIn(InputStream in, ClassLoader classLoader) throws IOException, ClassNotFoundException { return streamIn(in, classLoader, false); }
try { Thread.currentThread().setContextClassLoader( loader2 ); kpkgs2 = (Collection<KiePackage>) DroolsStreamUtils.streamIn( out );
try { Thread.currentThread().setContextClassLoader( loader2 ); kpkgs2 = (Collection<KiePackage>) DroolsStreamUtils.streamIn( out ); } finally { Thread.currentThread().setContextClassLoader( ccl );
/** * This method reads the contents from the given byte array and returns the object. The contents in the given * buffer could be compressed or uncompressed depending on the given flag. It is assumed that the content * stream was written by the corresponding streamOut methods of this class. * @param bytes * @param compressed * @return * @throws IOException * @throws ClassNotFoundException */ public static Object streamIn(byte[] bytes, boolean compressed) throws IOException, ClassNotFoundException { return streamIn(new ByteArrayInputStream(bytes), null, compressed); }
/** * This method reads the contents from the given byte array and returns the object. The contents in the given * buffer could be compressed or uncompressed depending on the given flag. It is assumed that the content * stream was written by the corresponding streamOut methods of this class. * @param bytes * @param classLoader * @param compressed * @return * @throws IOException * @throws ClassNotFoundException */ public static Object streamIn(byte[] bytes, ClassLoader classLoader, boolean compressed) throws IOException, ClassNotFoundException { return streamIn(new ByteArrayInputStream(bytes), classLoader, compressed); }
public Package fetchPackage(URL url, boolean enableBasicAuthentication, String username, String password) throws IOException, ClassNotFoundException { URLConnection con = url.openConnection(); HttpURLConnection httpCon = (HttpURLConnection) con; try { httpCon.setRequestMethod( "GET" ); if (enableBasicAuthentication) { String userpassword = username + ":" + password; byte[] authEncBytes = Base64.encodeBase64(userpassword .getBytes()); httpCon.setRequestProperty("Authorization", "Basic " + new String(authEncBytes)); } Object o = DroolsStreamUtils.streamIn( httpCon.getInputStream() ); if ( o instanceof KnowledgePackageImp ) { return ((KnowledgePackageImp) o).pkg; } else { return (Package) o; } } finally { httpCon.disconnect(); } }
public static <T> T serializeObject(T obj, ClassLoader classLoader) throws IOException, ClassNotFoundException { return (T) DroolsStreamUtils.streamIn( DroolsStreamUtils.streamOut( obj ), classLoader ); }
(GroupElement[]) DroolsStreamUtils.streamIn( new FileInputStream(testFile));
o = DroolsStreamUtils.streamIn( fis );
knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(); ((InternalKnowledgeBase) knowledgeBase).addPackages( (List<KiePackage>) DroolsStreamUtils.streamIn(resources.openRawResource(id))); kbases.put(annotation.value(), knowledgeBase);
DroolsStreamUtils.streamOut(new FileOutputStream(testFile), result); final GroupElement[] correctResultRoot = (GroupElement[]) DroolsStreamUtils.streamIn(new FileInputStream(testFile));