|
6 | 6 | import org.apache.poi.xssf.streaming.SXSSFSheet; |
7 | 7 | import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
8 | 8 | import org.junit.jupiter.api.BeforeAll; |
9 | | -import org.junit.jupiter.api.BeforeEach; |
10 | 9 | import org.junit.jupiter.api.Test; |
11 | 10 |
|
12 | | -import java.io.File; |
13 | | -import java.io.FileOutputStream; |
14 | | -import java.io.IOException; |
15 | | -import java.io.OutputStream; |
| 11 | +import java.io.*; |
16 | 12 | import java.util.logging.Logger; |
17 | 13 | import java.util.stream.Stream; |
18 | 14 |
|
19 | 15 | import static org.junit.jupiter.api.Assertions.assertEquals; |
20 | 16 |
|
21 | 17 | public class MemoryUsageTest { |
22 | 18 | private static final Logger LOG = Logger.getLogger(MemoryUsageTest.class.getName()); |
23 | | - private static final int ROWS = 600_000; |
| 19 | + private static final int ROWS = 600_001; |
24 | 20 | private static final int COLS = 200; |
25 | 21 | private static File testFile = new File("target/memtest" + ROWS + "x" + COLS + ".xlsx"); |
26 | 22 |
|
@@ -48,33 +44,42 @@ public static void generateBig() throws IOException { |
48 | 44 | LOG.info("Size: " + testFile.length()); |
49 | 45 | } |
50 | 46 |
|
51 | | - @BeforeEach |
52 | | - public void disableZipBombDetection() { |
| 47 | + @Test |
| 48 | + public void readFile() throws Exception { |
53 | 49 | ZipSecureFileWorkaround.disableZipBombDetection(); |
| 50 | + try (ReadableWorkbook wb = new ReadableWorkbook(testFile)) { |
| 51 | + fastexcelReader(wb); |
| 52 | + } |
54 | 53 | } |
55 | 54 |
|
56 | 55 | @Test |
57 | | - public void read() throws Exception { |
58 | | - try (ReadableWorkbook wb = new ReadableWorkbook(testFile)) { |
59 | | - org.dhatim.fastexcel.reader.Sheet sheet = wb.getFirstSheet(); |
60 | | - try (Stream<org.dhatim.fastexcel.reader.Row> rows = sheet.openStream()) { |
61 | | - rows.forEach(r -> { |
62 | | - printProgress("reading", r.getRowNum() - 1); |
63 | | - for (int c = 0; c < r.getCellCount(); c++) { |
64 | | - assertEquals( |
65 | | - valueFor(r.getRowNum() - 1, c), |
66 | | - r.getCell(c).asNumber().doubleValue(), |
67 | | - 1e-5); |
| 56 | + public void readInputStream() throws Exception { |
| 57 | + try (InputStream in = new FileInputStream(testFile); |
| 58 | + ReadableWorkbook wb = new ReadableWorkbook(in) |
| 59 | + ) { |
| 60 | + fastexcelReader(wb); |
| 61 | + } |
| 62 | + } |
68 | 63 |
|
69 | | - } |
70 | | - }); |
71 | | - } |
| 64 | + private void fastexcelReader(ReadableWorkbook wb) throws IOException { |
| 65 | + Sheet sheet = wb.getFirstSheet(); |
| 66 | + try (Stream<Row> rows = sheet.openStream()) { |
| 67 | + rows.forEach(r -> { |
| 68 | + printProgress("reading", r.getRowNum() - 1); |
| 69 | + for (int c = 0; c < r.getCellCount(); c++) { |
| 70 | + assertEquals( |
| 71 | + valueFor(r.getRowNum() - 1, c), |
| 72 | + r.getCell(c).asNumber().doubleValue(), |
| 73 | + 1e-5); |
| 74 | + |
| 75 | + } |
| 76 | + }); |
72 | 77 | } |
73 | 78 | } |
74 | 79 |
|
75 | 80 | private static void printProgress(String prefix, int r) { |
76 | 81 | if (r % (ROWS / 100) == 0) { |
77 | | - LOG.info(prefix+": "+(100 * r / ROWS) + "%"); |
| 82 | + LOG.info(prefix + ": " + (100 * r / ROWS) + "%"); |
78 | 83 | } |
79 | 84 | } |
80 | 85 |
|
|
0 commit comments