Search in sources :

Example 6 with PushbackReader

use of java.io.PushbackReader in project robovm by robovm.

the class OldPushbackReaderTest method test_ConstructorLjava_io_Reader.

/**
     * java.io.PushbackReader#PushbackReader(java.io.Reader)
     */
public void test_ConstructorLjava_io_Reader() {
    // Test for method java.io.PushbackReader(java.io.Reader)
    try {
        pbr.close();
        pbr = new PushbackReader(new StringReader(pbString));
        char[] buf = new char[5];
        pbr.read(buf, 0, 5);
        pbr.unread(buf);
        fail("Created reader with buffer larger than 1");
        ;
    } catch (IOException e) {
    // Expected
    }
    try {
        pbr = new PushbackReader(null);
    } catch (NullPointerException e) {
    // EXpected
    }
}
Also used : StringReader(java.io.StringReader) IOException(java.io.IOException) PushbackReader(java.io.PushbackReader)

Example 7 with PushbackReader

use of java.io.PushbackReader in project robovm by robovm.

the class OldPushbackReaderTest method test_ConstructorLjava_io_ReaderI.

/**
     * java.io.PushbackReader#PushbackReader(java.io.Reader, int)
     */
public void test_ConstructorLjava_io_ReaderI() throws IOException {
    PushbackReader tobj;
    tobj = new PushbackReader(underlying, 10000);
    tobj = new PushbackReader(underlying, 1);
    try {
        tobj = new PushbackReader(underlying, -1);
        tobj.close();
        fail("IOException not thrown.");
    } catch (IllegalArgumentException e) {
    // expected
    }
    try {
        tobj = new PushbackReader(underlying, 0);
        tobj.close();
        fail("IOException not thrown.");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : PushbackReader(java.io.PushbackReader)

Example 8 with PushbackReader

use of java.io.PushbackReader in project robovm by robovm.

the class OldPushbackReaderTest method test_read$CII.

/**
     * java.io.PushbackReader#read(char[], int, int)
     */
public void test_read$CII() throws IOException {
    PushbackReader tobj;
    char[] buf = ("01234567890123456789").toCharArray();
    tobj = new PushbackReader(underlying);
    tobj.read(buf, 6, 5);
    assertEquals("Wrong value read!", "BEGIN", new String(buf, 6, 5));
    assertEquals("Too much read!", "012345BEGIN123456789", new String(buf));
    underlying.throwExceptionOnNextUse = true;
    try {
        tobj.read(buf, 6, 5);
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
    // Test for method int java.io.PushbackReader.read(char [], int, int)
    try {
        char[] c = new char[5];
        pbr.read(c, 0, 5);
        assertTrue("Failed to read chars", new String(c).equals(pbString.substring(0, 5)));
        assertEquals(0, pbr.read(c, 0, 0));
        assertEquals(c.length, pbr.read(c, 0, c.length));
        assertEquals(0, pbr.read(c, c.length, 0));
    } catch (IOException e) {
        fail("IOException during read test : " + e.getMessage());
    }
}
Also used : IOException(java.io.IOException) PushbackReader(java.io.PushbackReader)

Example 9 with PushbackReader

use of java.io.PushbackReader in project j2objc by google.

the class OldAndroidPushbackReaderTest method testPushbackReader.

public void testPushbackReader() throws Exception {
    String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
    StringReader aa = new StringReader(str);
    StringReader ba = new StringReader(str);
    StringReader ca = new StringReader(str);
    PushbackReader a = new PushbackReader(aa, 5);
    try {
        a.unread("PUSH".toCharArray());
        Assert.assertEquals("PUSHAbCdEfGhIjKlMnOpQrStUvWxYz", read(a));
    } finally {
        a.close();
    }
    PushbackReader b = new PushbackReader(ba, 15);
    try {
        b.unread('X');
        Assert.assertEquals("XAbCdEfGhI", read(b, 10));
    } finally {
        b.close();
    }
    PushbackReader c = new PushbackReader(ca);
    try {
        Assert.assertEquals("bdfhjlnprtvxz", skipRead(c));
    } finally {
        c.close();
    }
}
Also used : StringReader(java.io.StringReader) PushbackReader(java.io.PushbackReader)

Example 10 with PushbackReader

use of java.io.PushbackReader in project j2objc by google.

the class OldPushbackReaderTest method test_unread_$CII_ArrayIndexOutOfBoundsException.

public void test_unread_$CII_ArrayIndexOutOfBoundsException() throws IOException {
    //a pushback reader with one character buffer
    pbr = new PushbackReader(new StringReader(pbString));
    try {
        pbr.unread(new char[pbString.length()], 0, -1);
        fail("should throw ArrayIndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        pbr.unread(new char[10], 10, 1);
        fail("should throw ArrayIndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
}
Also used : StringReader(java.io.StringReader) PushbackReader(java.io.PushbackReader)

Aggregations

PushbackReader (java.io.PushbackReader)37 IOException (java.io.IOException)22 StringReader (java.io.StringReader)12 CompileException (com.googlecode.prolog_cafe.exceptions.CompileException)3 JavaObjectTerm (com.googlecode.prolog_cafe.lang.JavaObjectTerm)3 SymbolTerm (com.googlecode.prolog_cafe.lang.SymbolTerm)3 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 StructureTerm (com.googlecode.prolog_cafe.lang.StructureTerm)2 FileNotFoundException (java.io.FileNotFoundException)2 LineNumberReader (java.io.LineNumberReader)2 Lexer (net.sourceforge.processdash.data.compiler.lexer.Lexer)2 Parser (net.sourceforge.processdash.data.compiler.parser.Parser)2 SyntaxException (com.googlecode.prolog_cafe.exceptions.SyntaxException)1 TermException (com.googlecode.prolog_cafe.exceptions.TermException)1 BufferingPrologControl (com.googlecode.prolog_cafe.lang.BufferingPrologControl)1 ListTerm (com.googlecode.prolog_cafe.lang.ListTerm)1 Term (com.googlecode.prolog_cafe.lang.Term)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1