From 84de0558db18a86cd8f58d5694e7edbfdc4dde40 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Thu, 9 Jun 2011 10:38:31 +0000 Subject: [PATCH] continue SXSSF docs updates and polishing git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1133782 13f79535-47bb-0310-9956-ffa450edef68 --- .../content/xdocs/spreadsheet/how-to.xml | 83 ++++++++++++++----- .../content/xdocs/spreadsheet/index.xml | 11 ++- .../xssf/usermodel/examples/BigGridDemo.java | 6 +- .../apache/poi/xssf/streaming/SXSSFSheet.java | 23 ++++- 4 files changed, 92 insertions(+), 31 deletions(-) diff --git a/src/documentation/content/xdocs/spreadsheet/how-to.xml b/src/documentation/content/xdocs/spreadsheet/how-to.xml index a8f6515315..d1957a957d 100644 --- a/src/documentation/content/xdocs/spreadsheet/how-to.xml +++ b/src/documentation/content/xdocs/spreadsheet/how-to.xml @@ -626,29 +626,38 @@ public class ExampleEventUserModel {
SXSSF (Streaming Usermodel API)

- XSSF is an API-compatible streaming extension of XSSF to be used when + SXSSF (package: org.apache.poi.xssf.streaming) is an API-compatible streaming extension of XSSF to be used when very large spreadsheets have to be produced, and heap space is limited. SXSSF achieves its low memory footprint by limiting access to the rows that are within a sliding window, while XSSF gives access to all rows in the document. Older rows that are no longer in the window become inaccessible, as they are written to the disk.

-

+

+ You can specify the window size at workbook construction time via new SXSSFWorkbook(int windowSize) + or you can set it per-sheet via SXSSFSheet#setRandomAccessWindowSize(int windowSize) +

+

When a new row is created via createRow() and the total number - of unflushed records would exeed the specified window size, then the + of unflushed records would exceed the specified window size, then the row with the lowest index value is flushed and cannot be accessed via getRow() anymore.

- A value of -1 indicates unlimited access. In this case all - records that have not been flushed by a call to flush() are available - for random access. + The default window size is 100 and defined by SXSSFWorkbook.DEFAULT_WINDOW_SIZE. +

+

+ A windowSize of -1 indicates unlimited access. In this case all + records that have not been flushed by a call to flushRows() are available + for random access.

- +

The example below writes a sheet with a window of 100 rows. When the row count reaches 101, + the row with rownum=0 is flushed to disk and removed from memory, when rownum reaches 102 then the row with rownum=1 is flushed, etc. +

+ + +

The next example turns off auto-flashing (windowSize=-1) and the code manually controls how portions of data are written to disk

+
diff --git a/src/documentation/content/xdocs/spreadsheet/index.xml b/src/documentation/content/xdocs/spreadsheet/index.xml index 514460106d..11e58d3b7e 100644 --- a/src/documentation/content/xdocs/spreadsheet/index.xml +++ b/src/documentation/content/xdocs/spreadsheet/index.xml @@ -79,10 +79,10 @@
-SXSSF (SInce POI 3.8 beta3) +SXSSF (Since POI 3.8 beta3)

Since 3.8-beta3, POI provides a low-memory footprint SXSSF API built on top of XSSF.

-XSSF is an API-compatible streaming extension of XSSF to be used when +SXSSF is an API-compatible streaming extension of XSSF to be used when very large spreadsheets have to be produced, and heap space is limited. SXSSF achieves its low memory footprint by limiting access to the rows that are within a sliding window, while XSSF gives access to all rows in the @@ -90,7 +90,10 @@ document. Older rows that are no longer in the window become inaccessible, as they are written to the disk.

-In auto-flush mode the size of the access window can be specified, to hold a certain number of rows in memory. When that value is reached, the creationof an additional row causes the row with the lowest index to to be removed from the access window and written to disk.. Or, the window size can be set to grow dynamically; it can be trimmed periodically by an explicit call to flush(int keepRows) as needed. +In auto-flush mode the size of the access window can be specified, to hold a certain number of rows in memory. +When that value is reached, the creation of an additional row causes the row with the lowest index to to be +removed from the access window and written to disk. Or, the window size can be set to grow dynamically; +it can be trimmed periodically by an explicit call to flushRows(int keepRows) as needed.

Due to the streaming nature of the implementation, there are the following @@ -102,6 +105,8 @@ limitations when compared to XSSF:

  • Formula evaluation is not supported
  • +

    See more details at SXSSF How-To

    +

    The table below synopsizes the comparative features of POI's Spreadsheet API:

    Spreadsheet API Feature Summary

    diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java index 91092232a9..00c5342746 100644 --- a/src/examples/src/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java +++ b/src/examples/src/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java @@ -37,7 +37,7 @@ import org.apache.poi.xssf.usermodel.*; * 3. Substitute the sheet in the template with the generated data * *

    - * Since 3.8-beta3 POI provides a low-memory footprint SXSSF API which implementing the "BigGridDemo" strategy. + * Since 3.8-beta3 POI provides a low-memory footprint SXSSF API which implementing the "BigGridDemo" strategy. * XSSF is an API-compatible streaming extension of XSSF to be used when * very large spreadsheets have to be produced, and heap space is limited. * SXSSF achieves its low memory footprint by limiting access to the rows that @@ -45,9 +45,11 @@ import org.apache.poi.xssf.usermodel.*; * document. Older rows that are no longer in the window become inaccessible, * as they are written to the disk. *

    + * See + * http://poi.apache.org/spreadsheet/how-to.html#sxssf. + * * @author Yegor Kozlov - * @see http://poi.apache.org/spreadsheet/how-to.html#sxssf */ public class BigGridDemo { private static final String XML_ENCODING = "UTF-8"; diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java index baea693418..f5d2dc4395 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java @@ -22,6 +22,7 @@ import java.util.Iterator; import java.util.TreeMap; import java.util.Map; +import org.apache.poi.hpsf.IllegalPropertySetDataException; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellReference; @@ -1179,20 +1180,34 @@ public class SXSSFSheet implements Sheet, Cloneable * A value of 0 is not allowed because it would flush any newly created row * without having a chance to specify any cells. */ - void setRandomAccessWindowSize(int value) + public void setRandomAccessWindowSize(int value) { - assert value!=0; + if(value == 0 || value < -1) { + throw new IllegalArgumentException("RandomAccessWindowSize must be either -1 or a positive integer"); + } _randomAccessWindowSize=value; } + /** * Specifies how many rows can be accessed at most via getRow(). * The exeeding rows (if any) are flushed to the disk while rows * with lower index values are flushed first. */ - void flushRows(int remaining) throws IOException + public void flushRows(int remaining) throws IOException + { + while(_rows.size() > remaining) flushOneRow(); + } + + /** + * Flush all rows to disk. After this call no rows can be accessed via getRow() + * + * @throws IOException + */ + public void flushRows() throws IOException { - while(_rows.size()>remaining) flushOneRow(); + this.flushRows(0); } + private void flushOneRow() throws IOException { Map.Entry firstEntry=_rows.firstEntry(); -- 2.39.5