From 6f46e92ba03c7b81bdb9de9c268f0d53a7c4e7f0 Mon Sep 17 00:00:00 2001 From: ChrisJoosse Date: Mon, 15 Sep 2025 16:09:49 -0700 Subject: [PATCH 1/3] Add helper to get rowCount from file --- src/org/labkey/test/TestFileUtils.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/org/labkey/test/TestFileUtils.java b/src/org/labkey/test/TestFileUtils.java index a860e0481e..71517414ac 100644 --- a/src/org/labkey/test/TestFileUtils.java +++ b/src/org/labkey/test/TestFileUtils.java @@ -44,10 +44,12 @@ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; +import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -118,6 +120,15 @@ public static String getFileContents(Path path) } } + public static int getFileRowCount(final File file) throws IOException + { + BufferedReader reader = new BufferedReader(new FileReader(file)); + int lines = 0; + while (reader.readLine() != null) lines++; + reader.close(); + return lines; + } + public static String getStreamContentsAsString(InputStream is) throws IOException { return StringUtils.join(IOUtils.readLines(is, Charset.defaultCharset()).toArray(), System.lineSeparator()); From 3d141462bd99573869d281be6925fd81af854970 Mon Sep 17 00:00:00 2001 From: Chris Joosse Date: Tue, 16 Sep 2025 10:02:48 -0700 Subject: [PATCH 2/3] Update src/org/labkey/test/TestFileUtils.java Co-authored-by: Trey Chadick --- src/org/labkey/test/TestFileUtils.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/org/labkey/test/TestFileUtils.java b/src/org/labkey/test/TestFileUtils.java index 71517414ac..52883d3d77 100644 --- a/src/org/labkey/test/TestFileUtils.java +++ b/src/org/labkey/test/TestFileUtils.java @@ -122,11 +122,12 @@ public static String getFileContents(Path path) public static int getFileRowCount(final File file) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(file)); - int lines = 0; - while (reader.readLine() != null) lines++; - reader.close(); - return lines; + try (BufferedReader reader = new BufferedReader(new FileReader(file))) + { + int lines = 0; + while (reader.readLine() != null) lines++; + return lines; + } } public static String getStreamContentsAsString(InputStream is) throws IOException From 9ec7d8174093dbd029e5dcbc191cd0e8bb00ad52 Mon Sep 17 00:00:00 2001 From: ChrisJoosse Date: Wed, 17 Sep 2025 15:18:54 -0700 Subject: [PATCH 3/3] cr feedback --- src/org/labkey/test/TestFileUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/labkey/test/TestFileUtils.java b/src/org/labkey/test/TestFileUtils.java index 52883d3d77..3af44b7639 100644 --- a/src/org/labkey/test/TestFileUtils.java +++ b/src/org/labkey/test/TestFileUtils.java @@ -120,11 +120,11 @@ public static String getFileContents(Path path) } } - public static int getFileRowCount(final File file) throws IOException + public static long getFileRowCount(final File file) throws IOException { try (BufferedReader reader = new BufferedReader(new FileReader(file))) { - int lines = 0; + long lines = 0; while (reader.readLine() != null) lines++; return lines; }