LineReader { public LineReader(final FSDataInputStream strm, final long start, final long length, final int buffersize) throws IOException { this.stream = strm; this.readBuffer = new byte[buffersize]; this.wrapBuffer = new byte[256]; this.lengthLeft = length; this.readPos = 0; this.overLimit = false; if (start != 0) { strm.seek(start); readLine(); } else { fillBuffer(); } } LineReader(final FSDataInputStream strm, final long start, final long length, final int buffersize); void close(); byte[] readLine();  }
@Test public void testLineReader() { final File testfile = new File(CommonTestUtils.getTempDir() + File.separator + CommonTestUtils.getRandomFilename()); final Path pathtotestfile = new Path(testfile.toURI().getPath()); try { PrintWriter pw = new PrintWriter(testfile, "UTF8"); for (int i = 0; i < 100; i++) { pw.append("line\n"); } pw.close(); LocalFileSystem lfs = new LocalFileSystem(); FSDataInputStream fis = lfs.open(pathtotestfile); final LineReader lr = new LineReader(fis, 0, testfile.length(), 256); byte[] buffer; int linecount = 0; while ((buffer = lr.readLine()) != null) { assertEquals(new String(buffer, "UTF8"), "line"); linecount++; } assertEquals(linecount, 100); } catch (Exception e) { fail(e.toString()); e.printStackTrace(); } finally { testfile.delete(); } }