/** You may copy this example and use it for any purpose, commercial or otherwise. */ import com.ricebridge.xmlman.in.XmlWriter; import java.util.Date; import java.util.Calendar; import java.util.Collections; import java.util.Arrays; import java.text.SimpleDateFormat; import java.io.File; import java.io.FileOutputStream; /** This is a utility class to generate arbitrarily large xml files * for use by the MakeTable class. Specify the number of data records * as the first argument. This creates a set of employees and projects * with predefined data fields. * * You can use different file sizes to compare the performance of the * MultipleBeansRecordListener and the StreamingMultipleBeansRecordListener, * particularly with regard to memory usage. * * To compile and run this program, you will need to include xmlman.jar * (in the lib folder of the XML Manager distribution) in your CLASSPATH. */ public class MakeReallyBigFile { public static void main( String[] args ) throws Exception { int numemps = 100000; if( 1 == args.length ) { numemps = Integer.parseInt(args[0]); } int part = numemps/10; part = 20 < part ? 20 : part; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); FileOutputStream fos = new FileOutputStream( new File("reallybig.xml") ); XmlWriter xmlw = new XmlWriter(); xmlw.setFlush( true ); xmlw.setIndent( true ); xmlw.setOutput( fos, "UTF-8"); int eI = 0; xmlw.startDocument(""); xmlw.startElement( "company", Collections.EMPTY_LIST, null ); for( eI = 0; eI < numemps; eI++ ) { if( 0 == eI % 1000 ) { System.out.println( "records: "+eI ); } xmlw.startElement( "employee", Arrays.asList(new String[]{"num",""+eI,"manager",""+(0==eI%part)}), null ); xmlw.startElement( "name", Collections.EMPTY_LIST, null ); xmlw.text( "John Doe "+eI ); xmlw.endElement( "name" ); Calendar c = Calendar.getInstance(); c.set( Calendar.DAY_OF_YEAR, eI); xmlw.startElement( "hired", Collections.EMPTY_LIST, null ); xmlw.text( sdf.format(c.getTime()) ); xmlw.endElement( "hired" ); String prjs = ""+(eI/part); if( 0==eI%part && ((eI/part)+1)<(numemps/10) ) { prjs += ":"+((eI/part)+1); } xmlw.startElement( "projects", Collections.EMPTY_LIST, null ); xmlw.text( prjs ); xmlw.endElement( "projects" ); xmlw.endElement( "employee"); if( 0==eI%part ) { xmlw.startElement( "project", Arrays.asList(new String[]{"num",""+(eI/part),"name","Project "+(eI/part)}), null ); xmlw.startElement( "deadline", Collections.EMPTY_LIST, null ); c.set( Calendar.MONTH, eI%part); xmlw.text( sdf.format(c.getTime()) ); xmlw.endElement( "deadline" ); StringBuffer emps = new StringBuffer(); boolean first = true; for( int i = (part*(eI/part)); i < part+(part*(eI/part)); i++ ) { emps.append( (first?"":":")+i ); first = false; } xmlw.startElement( "employees", Collections.EMPTY_LIST, null ); xmlw.text( emps.toString() ); xmlw.endElement( "employees" ); xmlw.endElement( "project"); } } xmlw.endElement("company"); xmlw.endDocument(""); System.out.println( "records: "+eI ); } }