=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java 2011-03-22 17:29:14 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java 2011-10-12 09:47:13 +0000 @@ -61,6 +61,11 @@ { private static final Log log = LogFactory.getLog( ExportPivotViewService.class ); + // The number of values to buffer before forcing attempt to flush + // Ideally this value should be set to a number of bytes say twice the size of the underlying buffer + // 500 is just a conservative thumbsuck + private static final int CHUNK = 500; + // service can export either aggregated datavalues or aggregated indicator values public enum RequestType { @@ -185,6 +190,9 @@ AggregatedDataValue adv = Iterator.next(); writer.write( "# period, orgunit, dataelement, catoptcombo, value\n" ); + + int values = 0; + while ( adv != null ) { int periodId = adv.getPeriodId(); @@ -196,6 +204,14 @@ writer.write( adv.getCategoryOptionComboId() + "," ); writer.write( adv.getValue() + "\n" ); + // defend against expanding the writer buffer uncontrollably + values = ++values % CHUNK; + + if (values == 0) + { + writer.flush(); + } + adv = Iterator.next(); } @@ -211,6 +227,8 @@ writer.write( "# period, orgunit, indicator, factor, numerator, denominator\n" ); + int values = 0; + while ( aiv != null ) { int periodId = aiv.getPeriodId(); @@ -223,6 +241,14 @@ writer.write( MathUtils.roundToString( aiv.getNumeratorValue(), PRECISION ) + "," ); writer.write( MathUtils.roundToString( aiv.getDenominatorValue(), PRECISION ) + "\n" ); + // defend against expanding the writer buffer uncontrollably + values = ++values % CHUNK; + + if (values == 0) + { + writer.flush(); + } + aiv = Iterator.next(); }