mirror of https://github.com/apache/poi.git
rename classes as DeferredSXSSF instead of EmittingSXSSF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1879484 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
be09639638
commit
9f8b864c41
|
@ -25,33 +25,34 @@ import org.apache.poi.util.Beta;
|
|||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
|
||||
/**
|
||||
* A variant of SXSSFSheet that uses IRowGenerator to create rows.
|
||||
* A variant of SXSSFSheet that uses a <code>RowGeneratorFunction</code></code> to lazily create rows.
|
||||
*
|
||||
* This variant is experimental and APIs may change at short notice.
|
||||
*
|
||||
* @see EmittingSXSSFWorkbook
|
||||
* @see DeferredSXSSFWorkbook
|
||||
* @see RowGeneratorFunction
|
||||
* @since 5.0.0
|
||||
*/
|
||||
@Beta
|
||||
public class EmittingSXSSFSheet extends SXSSFSheet {
|
||||
private IRowGenerator rowGenerator;
|
||||
public class DeferredSXSSFSheet extends SXSSFSheet {
|
||||
private RowGeneratorFunction rowGenerator;
|
||||
|
||||
public EmittingSXSSFSheet(EmittingSXSSFWorkbook workbook, XSSFSheet xSheet) throws IOException {
|
||||
public DeferredSXSSFSheet(DeferredSXSSFWorkbook workbook, XSSFSheet xSheet) throws IOException {
|
||||
super(workbook, xSheet, workbook.getRandomAccessWindowSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getWorksheetXMLInputStream() throws IOException {
|
||||
throw new RuntimeException("Not supported by EmittingSXSSFSheet");
|
||||
throw new RuntimeException("Not supported by DeferredSXSSFSheet");
|
||||
}
|
||||
|
||||
public void setRowGenerator(IRowGenerator rowGenerator) {
|
||||
public void setRowGenerator(RowGeneratorFunction rowGenerator) {
|
||||
this.rowGenerator = rowGenerator;
|
||||
}
|
||||
|
||||
public void writeRows(OutputStream out) throws IOException {
|
||||
// delayed creation of SheetDataWriter
|
||||
_writer = ((EmittingSXSSFWorkbook) _workbook).createSheetDataWriter(out);
|
||||
_writer = ((DeferredSXSSFWorkbook) _workbook).createSheetDataWriter(out);
|
||||
try {
|
||||
if (this.rowGenerator != null) {
|
||||
this.rowGenerator.generateRows(this);
|
|
@ -39,27 +39,27 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|||
* @since 5.0.0
|
||||
*/
|
||||
@Beta
|
||||
public class EmittingSXSSFWorkbook extends SXSSFWorkbook {
|
||||
private static final POILogger logger = POILogFactory.getLogger(EmittingSXSSFWorkbook.class);
|
||||
public class DeferredSXSSFWorkbook extends SXSSFWorkbook {
|
||||
private static final POILogger logger = POILogFactory.getLogger(DeferredSXSSFWorkbook.class);
|
||||
|
||||
public EmittingSXSSFWorkbook() {
|
||||
public DeferredSXSSFWorkbook() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public EmittingSXSSFWorkbook(int rowAccessWindowSize) { this(null, rowAccessWindowSize); }
|
||||
public DeferredSXSSFWorkbook(int rowAccessWindowSize) { this(null, rowAccessWindowSize); }
|
||||
|
||||
public EmittingSXSSFWorkbook(XSSFWorkbook workbook) {
|
||||
public DeferredSXSSFWorkbook(XSSFWorkbook workbook) {
|
||||
this(workbook, SXSSFWorkbook.DEFAULT_WINDOW_SIZE);
|
||||
}
|
||||
|
||||
public EmittingSXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize) {
|
||||
public DeferredSXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize) {
|
||||
super(workbook, rowAccessWindowSize, false, false);
|
||||
}
|
||||
|
||||
@NotImplemented
|
||||
@Override
|
||||
protected SheetDataWriter createSheetDataWriter() throws IOException {
|
||||
throw new RuntimeException("Not supported by EmittingSXSSFWorkbook");
|
||||
throw new RuntimeException("Not supported by DeferredSXSSFWorkbook");
|
||||
}
|
||||
|
||||
protected StreamingSheetWriter createSheetDataWriter(OutputStream out) throws IOException {
|
||||
|
@ -68,7 +68,7 @@ public class EmittingSXSSFWorkbook extends SXSSFWorkbook {
|
|||
|
||||
@Override
|
||||
protected ISheetInjector createSheetInjector(SXSSFSheet sxSheet) throws IOException {
|
||||
EmittingSXSSFSheet ssxSheet = (EmittingSXSSFSheet) sxSheet;
|
||||
DeferredSXSSFSheet ssxSheet = (DeferredSXSSFSheet) sxSheet;
|
||||
return (output) -> {
|
||||
ssxSheet.writeRows(output);
|
||||
};
|
||||
|
@ -76,9 +76,9 @@ public class EmittingSXSSFWorkbook extends SXSSFWorkbook {
|
|||
|
||||
@Override
|
||||
SXSSFSheet createAndRegisterSXSSFSheet(XSSFSheet xSheet) {
|
||||
final EmittingSXSSFSheet sxSheet;
|
||||
final DeferredSXSSFSheet sxSheet;
|
||||
try {
|
||||
sxSheet = new EmittingSXSSFSheet(this, xSheet);
|
||||
sxSheet = new DeferredSXSSFSheet(this, xSheet);
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
|
@ -86,12 +86,12 @@ public class EmittingSXSSFWorkbook extends SXSSFWorkbook {
|
|||
return sxSheet;
|
||||
}
|
||||
|
||||
public EmittingSXSSFSheet createSheet() {
|
||||
return (EmittingSXSSFSheet) super.createSheet();
|
||||
public DeferredSXSSFSheet createSheet() {
|
||||
return (DeferredSXSSFSheet) super.createSheet();
|
||||
}
|
||||
|
||||
public EmittingSXSSFSheet createSheet(String sheetname) {
|
||||
return (EmittingSXSSFSheet) super.createSheet(sheetname);
|
||||
public DeferredSXSSFSheet createSheet(String sheetname) {
|
||||
return (DeferredSXSSFSheet) super.createSheet(sheetname);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,7 +121,7 @@ public class EmittingSXSSFWorkbook extends SXSSFWorkbook {
|
|||
@SuppressWarnings("unchecked")
|
||||
public T next() throws NoSuchElementException {
|
||||
final XSSFSheet xssfSheet = it.next();
|
||||
EmittingSXSSFSheet sxSheet = (EmittingSXSSFSheet) getSXSSFSheet(xssfSheet);
|
||||
DeferredSXSSFSheet sxSheet = (DeferredSXSSFSheet) getSXSSFSheet(xssfSheet);
|
||||
return (T) (sxSheet == null ? xssfSheet : sxSheet);
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ public class EmittingSXSSFWorkbook extends SXSSFWorkbook {
|
|||
|
||||
@Override
|
||||
public SXSSFSheet getSheetAt(int index) {
|
||||
throw new RuntimeException("Not supported by EmittingSXSSFWorkbook");
|
||||
throw new RuntimeException("Not supported by DeferredSXSSFWorkbook");
|
||||
}
|
||||
|
||||
public XSSFSheet getXSSFSheetAt(int index) {
|
||||
|
@ -159,19 +159,19 @@ public class EmittingSXSSFWorkbook extends SXSSFWorkbook {
|
|||
* @param index the index
|
||||
* @return the streaming sheet at
|
||||
*/
|
||||
public EmittingSXSSFSheet getStreamingSheetAt(int index) {
|
||||
public DeferredSXSSFSheet getStreamingSheetAt(int index) {
|
||||
XSSFSheet xSheet = _wb.getSheetAt(index);
|
||||
SXSSFSheet sxSheet = getSXSSFSheet(xSheet);
|
||||
if (sxSheet == null && xSheet != null) {
|
||||
return (EmittingSXSSFSheet) createAndRegisterSXSSFSheet(xSheet);
|
||||
return (DeferredSXSSFSheet) createAndRegisterSXSSFSheet(xSheet);
|
||||
} else {
|
||||
return (EmittingSXSSFSheet) sxSheet;
|
||||
return (DeferredSXSSFSheet) sxSheet;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SXSSFSheet getSheet(String name) {
|
||||
throw new RuntimeException("Not supported by EmittingSXSSFWorkbook");
|
||||
throw new RuntimeException("Not supported by DeferredSXSSFWorkbook");
|
||||
}
|
||||
|
||||
public XSSFSheet getXSSFSheet(String name) {
|
||||
|
@ -184,11 +184,11 @@ public class EmittingSXSSFWorkbook extends SXSSFWorkbook {
|
|||
* @param name the name
|
||||
* @return the streaming sheet
|
||||
*/
|
||||
public EmittingSXSSFSheet getStreamingSheet(String name) {
|
||||
public DeferredSXSSFSheet getStreamingSheet(String name) {
|
||||
XSSFSheet xSheet = _wb.getSheet(name);
|
||||
EmittingSXSSFSheet sxSheet = (EmittingSXSSFSheet) getSXSSFSheet(xSheet);
|
||||
DeferredSXSSFSheet sxSheet = (DeferredSXSSFSheet) getSXSSFSheet(xSheet);
|
||||
if (sxSheet == null && xSheet != null) {
|
||||
return (EmittingSXSSFSheet) createAndRegisterSXSSFSheet(xSheet);
|
||||
return (DeferredSXSSFSheet) createAndRegisterSXSSFSheet(xSheet);
|
||||
} else {
|
||||
return sxSheet;
|
||||
}
|
|
@ -20,12 +20,12 @@ package org.apache.poi.xssf.streaming;
|
|||
import org.apache.poi.util.Beta;
|
||||
|
||||
/**
|
||||
* IRowGenerator for Emitting SXSSF sheets
|
||||
* RowGeneratorFunction for Deferred SXSSF sheets
|
||||
*
|
||||
* @see EmittingSXSSFWorkbook
|
||||
* @see DeferredSXSSFWorkbook
|
||||
*/
|
||||
@Beta
|
||||
public interface IRowGenerator {
|
||||
public interface RowGeneratorFunction {
|
||||
|
||||
/**
|
||||
* Generate and add rows to the sheet
|
|
@ -37,9 +37,9 @@ import java.io.IOException;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public final class TestEmittingSXSSFWorkbook extends BaseTestXWorkbook {
|
||||
public final class TestDeferredSXSSFWorkbook extends BaseTestXWorkbook {
|
||||
|
||||
public TestEmittingSXSSFWorkbook() {
|
||||
public TestDeferredSXSSFWorkbook() {
|
||||
super(SXSSFITestDataProvider.instance);
|
||||
}
|
||||
|
||||
|
@ -89,11 +89,11 @@ public final class TestEmittingSXSSFWorkbook extends BaseTestXWorkbook {
|
|||
public void existingWorkbook() throws IOException {
|
||||
XSSFWorkbook xssfWb1 = new XSSFWorkbook();
|
||||
xssfWb1.createSheet("S1");
|
||||
EmittingSXSSFWorkbook wb1 = new EmittingSXSSFWorkbook(xssfWb1);
|
||||
DeferredSXSSFWorkbook wb1 = new DeferredSXSSFWorkbook(xssfWb1);
|
||||
XSSFWorkbook xssfWb2 = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb1);
|
||||
assertTrue(wb1.dispose());
|
||||
|
||||
EmittingSXSSFWorkbook wb2 = new EmittingSXSSFWorkbook(xssfWb2);
|
||||
DeferredSXSSFWorkbook wb2 = new DeferredSXSSFWorkbook(xssfWb2);
|
||||
assertEquals(1, wb2.getNumberOfSheets());
|
||||
Sheet sheet = wb2.getStreamingSheetAt(0);
|
||||
assertNotNull(sheet);
|
||||
|
@ -108,7 +108,7 @@ public final class TestEmittingSXSSFWorkbook extends BaseTestXWorkbook {
|
|||
|
||||
@Test
|
||||
public void useSharedStringsTable() throws Exception {
|
||||
// not supported with EmittingSXSSF
|
||||
// not supported with DeferredSXSSF
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -119,14 +119,14 @@ public final class TestEmittingSXSSFWorkbook extends BaseTestXWorkbook {
|
|||
Row row = sheet.createRow(1);
|
||||
Cell cell = row.createCell(1);
|
||||
cell.setCellValue("value 2_1_1");
|
||||
EmittingSXSSFWorkbook wb1 = new EmittingSXSSFWorkbook(xssfWb1);
|
||||
DeferredSXSSFWorkbook wb1 = new DeferredSXSSFWorkbook(xssfWb1);
|
||||
XSSFWorkbook xssfWb2 = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb1);
|
||||
assertTrue(wb1.dispose());
|
||||
xssfWb1.close();
|
||||
|
||||
EmittingSXSSFWorkbook wb2 = new EmittingSXSSFWorkbook(xssfWb2);
|
||||
DeferredSXSSFWorkbook wb2 = new DeferredSXSSFWorkbook(xssfWb2);
|
||||
// Add a row to the existing empty sheet
|
||||
EmittingSXSSFSheet ssheet1 = wb2.getStreamingSheetAt(0);
|
||||
DeferredSXSSFSheet ssheet1 = wb2.getStreamingSheetAt(0);
|
||||
ssheet1.setRowGenerator((ssxSheet) -> {
|
||||
Row row1_1 = ssxSheet.createRow(1);
|
||||
Cell cell1_1_1 = row1_1.createCell(1);
|
||||
|
@ -134,14 +134,14 @@ public final class TestEmittingSXSSFWorkbook extends BaseTestXWorkbook {
|
|||
});
|
||||
|
||||
// Add a row to the existing non-empty sheet
|
||||
EmittingSXSSFSheet ssheet2 = wb2.getStreamingSheetAt(1);
|
||||
DeferredSXSSFSheet ssheet2 = wb2.getStreamingSheetAt(1);
|
||||
ssheet2.setRowGenerator((ssxSheet) -> {
|
||||
Row row2_2 = ssxSheet.createRow(2);
|
||||
Cell cell2_2_1 = row2_2.createCell(1);
|
||||
cell2_2_1.setCellValue("value 2_2_1");
|
||||
});
|
||||
// Add a sheet with one row
|
||||
EmittingSXSSFSheet ssheet3 = wb2.createSheet("S3");
|
||||
DeferredSXSSFSheet ssheet3 = wb2.createSheet("S3");
|
||||
ssheet3.setRowGenerator((ssxSheet) -> {
|
||||
Row row3_1 = ssxSheet.createRow(1);
|
||||
Cell cell3_1_1 = row3_1.createCell(1);
|
||||
|
@ -192,9 +192,9 @@ public final class TestEmittingSXSSFWorkbook extends BaseTestXWorkbook {
|
|||
|
||||
@Test
|
||||
public void sheetdataWriter() throws IOException {
|
||||
EmittingSXSSFWorkbook wb = new EmittingSXSSFWorkbook();
|
||||
DeferredSXSSFWorkbook wb = new DeferredSXSSFWorkbook();
|
||||
SXSSFSheet sh = wb.createSheet();
|
||||
assertSame(sh.getClass(), EmittingSXSSFSheet.class);
|
||||
assertSame(sh.getClass(), DeferredSXSSFSheet.class);
|
||||
SheetDataWriter wr = sh.getSheetDataWriter();
|
||||
assertNull(wr);
|
||||
wb.close();
|
||||
|
@ -202,7 +202,7 @@ public final class TestEmittingSXSSFWorkbook extends BaseTestXWorkbook {
|
|||
|
||||
@Test
|
||||
public void gzipSheetdataWriter() throws IOException {
|
||||
EmittingSXSSFWorkbook wb = new EmittingSXSSFWorkbook();
|
||||
DeferredSXSSFWorkbook wb = new DeferredSXSSFWorkbook();
|
||||
wb.setCompressTempFiles(true);
|
||||
|
||||
final int rowNum = 1000;
|
||||
|
@ -232,25 +232,25 @@ public final class TestEmittingSXSSFWorkbook extends BaseTestXWorkbook {
|
|||
wb.close();
|
||||
}
|
||||
|
||||
private static void assertWorkbookDispose(EmittingSXSSFWorkbook wb) {
|
||||
private static void assertWorkbookDispose(DeferredSXSSFWorkbook wb) {
|
||||
populateData(wb, 1000, 5);
|
||||
|
||||
for (Sheet sheet : wb) {
|
||||
EmittingSXSSFSheet sxSheet = (EmittingSXSSFSheet) sheet;
|
||||
DeferredSXSSFSheet sxSheet = (DeferredSXSSFSheet) sheet;
|
||||
assertNull(sxSheet.getSheetDataWriter());
|
||||
}
|
||||
|
||||
assertTrue(wb.dispose());
|
||||
|
||||
for (Sheet sheet : wb) {
|
||||
EmittingSXSSFSheet sxSheet = (EmittingSXSSFSheet) sheet;
|
||||
DeferredSXSSFSheet sxSheet = (DeferredSXSSFSheet) sheet;
|
||||
assertNull(sxSheet.getSheetDataWriter());
|
||||
}
|
||||
}
|
||||
|
||||
private static void populateData(EmittingSXSSFWorkbook wb, final int rowNum, final int sheetNum) {
|
||||
private static void populateData(DeferredSXSSFWorkbook wb, final int rowNum, final int sheetNum) {
|
||||
for (int i = 0; i < sheetNum; i++) {
|
||||
EmittingSXSSFSheet sheet = wb.createSheet("sheet" + i);
|
||||
DeferredSXSSFSheet sheet = wb.createSheet("sheet" + i);
|
||||
int index = i;
|
||||
sheet.setRowGenerator((sh) -> {
|
||||
for (int j = 0; j < rowNum; j++) {
|
||||
|
@ -270,12 +270,12 @@ public final class TestEmittingSXSSFWorkbook extends BaseTestXWorkbook {
|
|||
|
||||
@Test
|
||||
public void workbookDispose() throws IOException {
|
||||
EmittingSXSSFWorkbook wb1 = new EmittingSXSSFWorkbook();
|
||||
DeferredSXSSFWorkbook wb1 = new DeferredSXSSFWorkbook();
|
||||
// the underlying writer is SheetDataWriter
|
||||
assertWorkbookDispose(wb1);
|
||||
wb1.close();
|
||||
|
||||
EmittingSXSSFWorkbook wb2 = new EmittingSXSSFWorkbook();
|
||||
DeferredSXSSFWorkbook wb2 = new DeferredSXSSFWorkbook();
|
||||
wb2.setCompressTempFiles(true);
|
||||
// the underlying writer is GZIPSheetDataWriter
|
||||
assertWorkbookDispose(wb2);
|
Loading…
Reference in New Issue