From 93c599be72a1049e7c22489523b92349ab687779 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Wed, 8 Jun 2011 12:38:07 +0000 Subject: [PATCH] SXSSF documentation and polishing git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1133372 13f79535-47bb-0310-9956-ffa450edef68 --- .../content/xdocs/spreadsheet/how-to.xml | 69 ++++++++++++++++++ .../content/xdocs/spreadsheet/index.xml | 38 +++++++++- .../resources/images/ss-features.png | Bin 0 -> 13173 bytes .../xssf/usermodel/examples/BigGridDemo.java | 11 +++ .../apache/poi/xssf/streaming/SXSSFSheet.java | 16 ++-- .../poi/xssf/streaming/SXSSFWorkbook.java | 46 ++++++++++++ 6 files changed, 169 insertions(+), 11 deletions(-) create mode 100644 src/documentation/resources/images/ss-features.png diff --git a/src/documentation/content/xdocs/spreadsheet/how-to.xml b/src/documentation/content/xdocs/spreadsheet/how-to.xml index 35e4a0003..a8f651531 100644 --- a/src/documentation/content/xdocs/spreadsheet/how-to.xml +++ b/src/documentation/content/xdocs/spreadsheet/how-to.xml @@ -58,6 +58,7 @@
  • Event API (HSSF Only)
  • Event API with extensions to be Record Aware (HSSF Only)
  • XSSF and SAX (Event API)
  • +
  • SXSSF (Streaming User API)
  • Low Level API
  • @@ -620,6 +621,74 @@ public class ExampleEventUserModel { howto.processAllSheets(args[0]); } } +]]> + + +
    SXSSF (Streaming Usermodel API) +

    + 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 + 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. +

    +

    + When a new row is created via createRow() and the total number + of unflushed records would exeed 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. +

    + +
    diff --git a/src/documentation/content/xdocs/spreadsheet/index.xml b/src/documentation/content/xdocs/spreadsheet/index.xml index f52d60c3d..514460106 100644 --- a/src/documentation/content/xdocs/spreadsheet/index.xml +++ b/src/documentation/content/xdocs/spreadsheet/index.xml @@ -73,6 +73,42 @@ the memory footprint for processing them is higher than for the older HSSF supported (.xls) binary files.

    + + + - + +
    +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 +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. +

    +

    +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. +

    +

    +Due to the streaming nature of the implementation, there are the following +limitations when compared to XSSF: +

    +
      +
    • Only a limited number of rows are accessible at a point in time.
    • +
    • Sheet.clone() is not supported.
    • +
    • Formula evaluation is not supported
    • +
    + +

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

    +

    Spreadsheet API Feature Summary

    + +

    + Spreadsheet API Feature Summary +

    +
    + + diff --git a/src/documentation/resources/images/ss-features.png b/src/documentation/resources/images/ss-features.png new file mode 100644 index 0000000000000000000000000000000000000000..17554c71514f7c4445c51f12ed0821bc7837c2d6 GIT binary patch literal 13173 zcmbt)bySpZ*Y1c2NH+|Pbi>dc5~73(3`on+BHi5x4BcHKN)O$jz|aCB-3`*skZ17s zzTf)3^PY45Ijl8{^~~JQo!7nhwXeOyU#ltMU{YWL001227xHfb02Da@;L#Hd6y!Jl z_Ovv}e~+BrD#-!Le^PBDA5bl1Rb>GHSPa(9`zOffr}i)2IROB;oe!T!J$7GB0RVnX zWqDamcf&mc@w)YfxLv`sQLBPFUP{XXoOgC4j;4KOIK3YeBaTe*2nN!|iv+V>x%{>bu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<+Gc zq2k%{#@>SGrX_Fcv5}g;=^<|;Nv;bhmo*xQEU)J8D2`NW(@^I5hXQ&4gUmqqdrKuYY8Hw(40`^2A>$|8F$$>bYl4)v$9z%C8+t5GiLPzcRNQX{UAR z@uw;&kMG2PtX>_APTihfllCGNg!aF#bQdZ2o1I=EPjK^?koK6^H4H>LshdPEP`YKr z=a}-)P&=dGdigwMm~&r+Q&F+}gY)mAbFHB?g}! zf%Mi~QIR8SKUr>l$aiufowr-i$5EB+zgWLmxxL(1cWGdGk4UVz#{qUu@`&_warAHW zxm9d6Z72qUhjy)ZDNR)vN=mMRz3VZz3(x!~3hfK3W-*}sQ+p9_{85m=Adb~>d-VVC ljri?F0Y?8-F-;h7kDgH5btRvKi3dRbDJ!VSm&+Lk{x9Ryg0}zw literal 0 HcmV?d00001 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 723c424fd..91092232a 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 @@ -36,7 +36,18 @@ import org.apache.poi.xssf.usermodel.*; * 2. create an application that streams data in a text file * 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. + * 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 + * 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. + *

    + * * @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 be90606e1..baea69341 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java @@ -17,15 +17,10 @@ package org.apache.poi.xssf.streaming; +import java.io.*; import java.util.Iterator; import java.util.TreeMap; import java.util.Map; -import java.io.Writer; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.FileInputStream; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellReference; @@ -46,7 +41,7 @@ public class SXSSFSheet implements Sheet, Cloneable XSSFSheet _sh; TreeMap _rows=new TreeMap(); SheetDataWriter _writer; - int _randomAccessWindowSize=5000; + int _randomAccessWindowSize = SXSSFWorkbook.DEFAULT_WINDOW_SIZE; public SXSSFSheet(SXSSFWorkbook workbook,XSSFSheet xSheet) throws IOException { @@ -1243,7 +1238,7 @@ public class SXSSFSheet implements Sheet, Cloneable { _fd = File.createTempFile("sheet", ".xml"); _fd.deleteOnExit(); - _out = new FileWriter(_fd); + _out = new BufferedWriter(new FileWriter(_fd)); _out.write("\n"); } public int getNumberOfFlushedRows() @@ -1262,9 +1257,10 @@ public class SXSSFSheet implements Sheet, Cloneable { _fd.delete(); } - public InputStream getWorksheetXMLInputStream() throws IOException + public InputStream getWorksheetXMLInputStream() throws IOException { _out.write(""); + _out.flush(); _out.close(); return new FileInputStream(_fd); } @@ -1275,7 +1271,7 @@ public class SXSSFSheet implements Sheet, Cloneable * @param rownum 0-based row number * @param row a row */ - public void writeRow(int rownum,SXSSFRow row) throws IOException + public void writeRow(int rownum,SXSSFRow row) throws IOException { if(_numberOfFlushedRows==0) _lowestIndexOfFlushedRows=rownum; diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java index aa17b536a..365e58b33 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java @@ -50,11 +50,56 @@ import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; */ public class SXSSFWorkbook implements Workbook { + /** + * Specifies how many rows can be accessed at most via getRow(). + * When a new node is created via createRow() and the total number + * of unflushed records would exeed the specified value, then the + * row with the lowest index value is flushed and cannot be accessed + * via getRow() anymore. + */ + public static final int DEFAULT_WINDOW_SIZE = 100; + XSSFWorkbook _wb=new XSSFWorkbook(); HashMap _sxFromXHash=new HashMap(); HashMap _xFromSxHash=new HashMap(); + int _randomAccessWindowSize = DEFAULT_WINDOW_SIZE; + + /** + * Construct a new workbook + */ + public SXSSFWorkbook(){ + + } + + /** + * Construct an empty workbook and specify the window for row access. + *

    + * When a new node is created via createRow() and the total number + * of unflushed records would exeed the specified value, 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. + *

    + *

    + * A value of 0 is not allowed because it would flush any newly created row + * without having a chance to specify any cells. + *

    + * + * @param rowAccessWindowSize + */ + public SXSSFWorkbook(int rowAccessWindowSize){ + if(rowAccessWindowSize == 0 || rowAccessWindowSize < -1) { + throw new IllegalArgumentException("rowAccessWindowSize must be greater than 0 or -1"); + } + _randomAccessWindowSize = rowAccessWindowSize; + } + XSSFSheet getXSSFSheet(SXSSFSheet sheet) { XSSFSheet result=_sxFromXHash.get(sheet); @@ -303,6 +348,7 @@ public class SXSSFWorkbook implements Workbook { throw new RuntimeException(ioe); } + sxSheet.setRandomAccessWindowSize(_randomAccessWindowSize); registerSheetMapping(sxSheet,xSheet); return sxSheet; }