]> source.dussan.org Git - poi.git/commitdiff
Bug 62872 - Writing large files with 800k rows gives java.io.IOException: This archiv...
authorAndreas Beeker <kiwiwings@apache.org>
Fri, 2 Nov 2018 22:59:58 +0000 (22:59 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Fri, 2 Nov 2018 22:59:58 +0000 (22:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1845629 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java

index 6fbcb140353a86dc288e77a67e4a1cdcd1339c55..ed52e0e16bd52b9b254db32d666a0e88c8d28bdc 100644 (file)
@@ -381,7 +381,10 @@ public class SXSSFWorkbook implements Workbook {
             Enumeration<? extends ZipArchiveEntry> en = zipEntrySource.getEntries();
             while (en.hasMoreElements()) {
                 ZipArchiveEntry ze = en.nextElement();
-                zos.putArchiveEntry(new ZipArchiveEntry(ze.getName()));
+                ZipArchiveEntry zeOut = new ZipArchiveEntry(ze.getName());
+                zeOut.setSize(ze.getSize());
+                zeOut.setTime(ze.getTime());
+                zos.putArchiveEntry(zeOut);
                 try (final InputStream is = zipEntrySource.getInputStream(ze)) {
                     if (is instanceof ZipArchiveThresholdInputStream) {
                         // #59743 - disable Threshold handling for SXSSF copy
index 3958aa2f6e98f04bf23b733cc1321c62b9f991b1..73d56c7a77776833db78e1ba877bf5279d2b0c53 100644 (file)
@@ -21,7 +21,10 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.Date;
 
 import org.apache.poi.ss.ITestDataProvider;
 import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
@@ -34,6 +37,9 @@ import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.SXSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.apache.poi.xssf.streaming.SXSSFCell;
+import org.apache.poi.xssf.streaming.SXSSFRow;
+import org.apache.poi.xssf.streaming.SXSSFSheet;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -166,4 +172,45 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues {
         CellRangeAddress range = new CellRangeAddress(rowIndex, rowIndex, colIndex, colIndex);
         sheet.setArrayFormula(col1Value, range);
     }
+
+    @Test
+    @Ignore("takes too long for the normal test run")
+    public void test62872() throws Exception {
+        final int COLUMN_COUNT = 300;
+        final int ROW_COUNT = 600000;
+        final int TEN_MINUTES = 1000*60*10;
+
+        SXSSFWorkbook workbook = new SXSSFWorkbook(100);
+        workbook.setCompressTempFiles(true);
+        SXSSFSheet sheet = workbook.createSheet("RawData");
+
+        SXSSFRow row = sheet.createRow(0);
+        SXSSFCell cell;
+
+        for (int i = 1; i <= COLUMN_COUNT; i++) {
+            cell = row.createCell(i - 1);
+            cell.setCellValue("Column " + i);
+        }
+
+        for (int i = 1; i < ROW_COUNT; i++) {
+            row = sheet.createRow(i);
+            for (int j = 1; j <= COLUMN_COUNT; j++) {
+                cell = row.createCell(j - 1);
+
+                //make some noise
+                cell.setCellValue(new Date(i*TEN_MINUTES+(j*TEN_MINUTES)/COLUMN_COUNT));
+            }
+            i++;
+            // if (i % 1000 == 0)
+            // logger.info("Created Row " + i);
+        }
+
+        try (FileOutputStream out = new FileOutputStream(File.createTempFile("test62872", ".xlsx"))) {
+            workbook.write(out);
+            workbook.dispose();
+            workbook.close();
+            out.flush();
+        }
+        // logger.info("File written!");
+    }
 }