Code example for LineNumberReader

Methods: getLineNumber, readLine

0
 
    /** 
     * @tests java.io.LineNumberReader#readLine() 
     */ 
    public void test_readLine() throws IOException { 
        lnr = new LineNumberReader(new StringReader(text));
        assertEquals("Returned incorrect line number", 0, lnr.getLineNumber());
        String line = null;
        lnr.readLine();
        line = lnr.readLine();
 
        assertEquals("Returned incorrect string", "1", line);
        assertTrue("Returned incorrect line number :" + lnr.getLineNumber(),
                lnr.getLineNumber() == 2);
 
        // Regression for HARMONY-4294 
        byte[] buffer = new byte[] { '\r', '\n' };
        LineNumberReader reader = new LineNumberReader(new InputStreamReader(
                new ByteArrayInputStream(buffer), "UTF-8"));
        assertEquals('\n', reader.read());
        assertEquals(-1, reader.read());