Web-Harvest the best, the good, the fast – way to save information

Doesn`t  matter you want to save xml file,  pictures, html or any other format of file the best way to do that is to use Java/Groovy function with Web-harvest :

A : The built-in function

I know it looks much easier to use simple built-in tag/function from WebHarvest :

<file action="write" path="${storeDir}/${attachText}.pdf" type="binary"> 
	<get var="content_you_want_to_save"> 		

BUT is not the best way – REASONS:

  • 1. Memory used – big disadvantage if you don`t have an endless memory machine :)
  • 2. Fast? well the java function is much faster than the built-in function for save

B : The Java function

<function name="saveFile" >
		<script language="groovy">
			import java.io.*;

            java.io.InputStream is = new ByteArrayInputStream(myContent.toBinary());
			java.io.BufferedInputStream getIt = new java.io.BufferedInputStream(is);
			java.io.FileOutputStream fos = new java.io.FileOutputStream( mySavePath.toString() );
	        java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
	        byte[] data = new byte[1024];
	        int x=0;
	        while((x=getIt.read(data,0,1024))>=0) {

how to call this function in WebHarvest :

<call name="saveFil2">
   <call-param name="mySavePath"><get var="filePath"/></call-param>
   <call-param name="myContent"><get var="content_you_want_to_save"/></call-param>
This entry was posted in Web Harvest. Bookmark the permalink.