Java Code Examples for java.io.LineNumberReader#reset()

The following examples show how to use java.io.LineNumberReader#reset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IrTransImporter.java    From IrScrutinizer with GNU General Public License v3.0 6 votes vote down vote up
private boolean gobbleTo(LineNumberReader reader, String target, boolean throwException) throws IOException, ParseException {
    String line = "";
    reader.mark(255);
    while (line.isEmpty()) {
        line = reader.readLine();
        if (line == null)
            return false;
    }
    if (!line.trim().equals(target)) {
        if (throwException)
            throw new ParseException(target + " not found.", reader.getLineNumber());
        else {
            reader.reset();
            return false;
        }
    }
    return true;
}
 
Example 2
Source File: OldLineNumberReaderTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void test_markI() throws IOException {
    lnr = new LineNumberReader(new StringReader(text));
    String line;
    lnr.skip(80);
    lnr.mark(100);
    line = lnr.readLine();
    lnr.reset();
    assertTrue("Test 1: Failed to return to marked position.",
            line.equals(lnr.readLine()));

    lnr.close();
    try {
        lnr.mark(42);
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
        // Expected.
    }

    // The spec does not say the mark has to be invalidated
}
 
Example 3
Source File: OldLineNumberReaderTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void test_reset() throws IOException {
    lnr = new LineNumberReader(new StringReader(text));
    assertEquals("Test 1: Returned incorrect line number;",
            0, lnr.getLineNumber());
    String line = null;
    lnr.mark(100);
    lnr.readLine();
    lnr.reset();
    line = lnr.readLine();
    assertEquals("Test 2: Failed to reset reader", "0", line);

    lnr.mark(100);
    lnr.close();
    try {
        lnr.reset();
        fail("Test 3: IOException expected.");
    } catch (IOException e) {
        // Expected.
    }
}