<NME> StreamingSheetTest.java
<BEF> ADDFILE
<MSG> Merge pull request #56 from edgraaff/master

Added support for sheet.getLastRowNum()
<DFF> @@ -0,0 +1,42 @@
+package com.monitorjbl.xlsx;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Locale;
+
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class StreamingSheetTest {
+  @BeforeClass
+  public static void init() {
+    Locale.setDefault(Locale.ENGLISH);
+  }
+
+  @Test
+  public void testLastRowNum() throws Exception {
+    try(
+        InputStream is = new FileInputStream(new File("src/test/resources/large.xlsx"));
+        Workbook workbook = StreamingReader.builder().open(is);
+    ) {
+      assertEquals(1, workbook.getNumberOfSheets());
+      Sheet sheet = workbook.getSheetAt(0);
+      assertEquals(24, sheet.getLastRowNum());
+    }
+
+    try(
+        InputStream is = new FileInputStream(new File("src/test/resources/empty_sheet.xlsx"));
+        Workbook workbook = StreamingReader.builder().open(is);
+    ) {
+      assertEquals(1, workbook.getNumberOfSheets());
+      Sheet sheet = workbook.getSheetAt(0);
+      assertEquals(0, sheet.getLastRowNum());
+    }
+  }
+
+}

{'commit': 'diff --git a/src/main/java/com/monitorjbl/xlsx/impl/StreamingSheet.java b/src/main/java/com/monitorjbl/xlsx/impl/StreamingSheet.java\nindex 3ae06cd..5225213 100644\n--- a/src/main/java/com/monitorjbl/xlsx/impl/StreamingSheet.java\n+++ b/src/main/java/com/monitorjbl/xlsx/impl/StreamingSheet.java\n@@ -115,11 +115,13 @@ public class StreamingSheet implements Sheet {\n   }\n \n   /**\n-   * Not supported\n+   * Gets the last row on the sheet\n+   *\n+   * @return last row contained n this sheet (0-based)\n    */\n   @Override\n   public int getLastRowNum() {\n-    throw new UnsupportedOperationException();\n+    return reader.getLastRowNum();\n   }\n \n   /**\ndiff --git a/src/main/java/com/monitorjbl/xlsx/impl/StreamingSheetReader.java b/src/main/java/com/monitorjbl/xlsx/impl/StreamingSheetReader.java\nindex 12d1dc4..894ee30 100644\n--- a/src/main/java/com/monitorjbl/xlsx/impl/StreamingSheetReader.java\n+++ b/src/main/java/com/monitorjbl/xlsx/impl/StreamingSheetReader.java\n@@ -42,6 +42,7 @@ public class StreamingSheetReader implements Iterable<Row> {\n   private final DataFormatter dataFormatter = new DataFormatter();\n   private final Set<Integer> hiddenColumns = new HashSet<>();\n \n+  private int lastRowNum;\n   private int rowCacheSize;\n   private List<Row> rowCache = new ArrayList<>();\n   private Iterator<Row> rowCacheIterator;\n@@ -131,6 +132,20 @@ public class StreamingSheetReader implements Iterable<Row> {\n             log.warn("Ignoring invalid style index {}", indexStr);\n           }\n         }\n+      } else if ("dimension".equals(tagLocalName)) {\n+        Attribute refAttr = startElement.getAttributeByName(new QName("ref"));\n+        String ref = refAttr!=null?refAttr.getValue():null;\n+        if (ref!=null) {\n+          // ref is formatted as A1 or A1:F25. Take the last numbers of this string and use it as lastRowNum\n+          for (int i=ref.length()-1;i>=0;i--) {\n+            if (!Character.isDigit(ref.charAt(i))) {\n+            try {\n+                lastRowNum = Integer.parseInt(ref.substring(i+1)) - 1;\n+            } catch (NumberFormatException ignore) { }\n+              break;\n+            }\n+          }\n+        }\n       }\n \n       // Clear contents cache\n@@ -164,6 +179,18 @@ public class StreamingSheetReader implements Iterable<Row> {\n     return hiddenColumns.contains(columnIndex);\n   }\n \n+  /**\n+   * Gets the last row on the sheet\n+   *\n+   * @return\n+   */\n+  int getLastRowNum() {\n+    if(rowCacheIterator == null) {\n+      getRow();\n+    }\n+    return lastRowNum;\n+  }\n+\n   /**\n    * Read the numeric format string out of the styles table for this cell. Stores\n    * the result in the Cell.\ndiff --git a/src/test/java/com/monitorjbl/xlsx/StreamingSheetTest.java b/src/test/java/com/monitorjbl/xlsx/StreamingSheetTest.java\nnew file mode 100644\nindex 0000000..6b0b162\n--- /dev/null\n+++ b/src/test/java/com/monitorjbl/xlsx/StreamingSheetTest.java\n@@ -0,0 +1,42 @@\n+package com.monitorjbl.xlsx;\n+\n+import static org.junit.Assert.assertEquals;\n+\n+import java.io.File;\n+import java.io.FileInputStream;\n+import java.io.InputStream;\n+import java.util.Locale;\n+\n+import org.apache.poi.ss.usermodel.Sheet;\n+import org.apache.poi.ss.usermodel.Workbook;\n+import org.junit.BeforeClass;\n+import org.junit.Test;\n+\n+public class StreamingSheetTest {\n+  @BeforeClass\n+  public static void init() {\n+    Locale.setDefault(Locale.ENGLISH);\n+  }\n+\n+  @Test\n+  public void testLastRowNum() throws Exception {\n+    try(\n+        InputStream is = new FileInputStream(new File("src/test/resources/large.xlsx"));\n+        Workbook workbook = StreamingReader.builder().open(is);\n+    ) {\n+      assertEquals(1, workbook.getNumberOfSheets());\n+      Sheet sheet = workbook.getSheetAt(0);\n+      assertEquals(24, sheet.getLastRowNum());\n+    }\n+\n+    try(\n+        InputStream is = new FileInputStream(new File("src/test/resources/empty_sheet.xlsx"));\n+        Workbook workbook = StreamingReader.builder().open(is);\n+    ) {\n+      assertEquals(1, workbook.getNumberOfSheets());\n+      Sheet sheet = workbook.getSheetAt(0);\n+      assertEquals(0, sheet.getLastRowNum());\n+    }\n+  }\n+\n+}\n', 'commit_subject': 'Merge pull request #56 from edgraaff/master', 'repo_name': 'monitorjbl/excel-streaming-reader', 'committer': {'name': 'GitHub', 'email': '1505422b2465e9a84f6fdfaa161078890c593f06@github.com', 'time_sec': '1474904763', 'tz_offset': '-240', 'date': {'seconds': '1474904763'}}, 'commit_tree': 'a84b07562bbe89d83d6736dedf7a50a374782d00', 'commit_message': 'Merge pull request #56 from edgraaff/master\n\nAdded support for sheet.getLastRowNum()', 'language_name': 'Java', 'license': 'apache-2.0', 'hunks': '@@ -0,0 +1,42 @@\n+package com.monitorjbl.xlsx;\n+\n+import static org.junit.Assert.assertEquals;\n+\n+import java.io.File;\n+import java.io.FileInputStream;\n+import java.io.InputStream;\n+import java.util.Locale;\n+\n+import org.apache.poi.ss.usermodel.Sheet;\n+import org.apache.poi.ss.usermodel.Workbook;\n+import org.junit.BeforeClass;\n+import org.junit.Test;\n+\n+public class StreamingSheetTest {\n+  @BeforeClass\n+  public static void init() {\n+    Locale.setDefault(Locale.ENGLISH);\n+  }\n+\n+  @Test\n+  public void testLastRowNum() throws Exception {\n+    try(\n+        InputStream is = new FileInputStream(new File("src/test/resources/large.xlsx"));\n+        Workbook workbook = StreamingReader.builder().open(is);\n+    ) {\n+      assertEquals(1, workbook.getNumberOfSheets());\n+      Sheet sheet = workbook.getSheetAt(0);\n+      assertEquals(24, sheet.getLastRowNum());\n+    }\n+\n+    try(\n+        InputStream is = new FileInputStream(new File("src/test/resources/empty_sheet.xlsx"));\n+        Workbook workbook = StreamingReader.builder().open(is);\n+    ) {\n+      assertEquals(1, workbook.getNumberOfSheets());\n+      Sheet sheet = workbook.getSheetAt(0);\n+      assertEquals(0, sheet.getLastRowNum());\n+    }\n+  }\n+\n+}\n', 'addition_count': 42, 'deletion_count': 0, 'src_file': '/dev/null', 'tgt_file': 'b/src/test/java/com/monitorjbl/xlsx/StreamingSheetTest.java', 'file_extension': '.java', 'before_file': 'ADDFILE', 'message': 'Merge pull request #56 from edgraaff/master\n\nAdded support for sheet.getLastRowNum()', 'author_name': 'GitHub', 'lang': 'java'}