public final void testReadBySection() throws IOException, BatchException { int[] lineCounts = new int[] {10, 1000, 10000, 100000, 1000000}; Padding pad = new Padding("*", 10); for (int lc : lineCounts) { File testFile = genererateTestFile(lc, pad); System.out.println("Test file " + testFile.getAbsolutePath() + " (" + lc + " lines)"); try { TestReader bfr = new TestReader(testFile.getAbsolutePath(), 1000, true); long readCount = 0; while (true) { InputFileSection<TestInputLine> section = bfr.readSection(); long linesRead = section.getLines().size(); boolean lastSection = section.noMoreInput(); if (!lastSection) { assertEquals(1000, linesRead); } else { assertTrue(linesRead <= 1000); } readCount += linesRead; if (lastSection) { break; } } assertEquals(lc, readCount); } finally { if (!testFile.delete()) { testFile.deleteOnExit(); } } } }
public final void testReadLineByLine() throws IOException, BatchException { int[] lineCounts = new int[] {10, 100, 1000, 10000, 100000}; Padding pad = new Padding("*", 10); for (int lc : lineCounts) { File testFile = genererateTestFile(lc, pad); System.out.println("Test file " + testFile.getAbsolutePath() + " (" + lc + " lines)"); try { TestReader bfr = new TestReader(testFile.getAbsolutePath(), 5, true); long readCount = 0; while (bfr.readLine() != null) { readCount++; } assertEquals(lc, readCount); } finally { if (!testFile.delete()) { testFile.deleteOnExit(); } } } }