Search in sources :

Example 26 with PushbackReader

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

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 27 with PushbackReader

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

the class OldPushbackReaderTest method test_close.

/**
     * java.io.PushbackReader#close()
     */
public void test_close() throws IOException {
    PushbackReader tobj;
    tobj = new PushbackReader(underlying);
    tobj.close();
    tobj.close();
    tobj = new PushbackReader(underlying);
    underlying.throwExceptionOnNextUse = true;
    try {
        tobj.close();
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
}
Also used : IOException(java.io.IOException) PushbackReader(java.io.PushbackReader)

Example 28 with PushbackReader

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

the class OldPushbackReaderTest method test_unreadI.

/**
     * java.io.PushbackReader#unread(int)
     */
public void test_unreadI() throws IOException {
    PushbackReader tobj;
    tobj = new PushbackReader(underlying);
    // Why does this work?!?
    tobj.unread(23);
    tobj.skip(2);
    tobj.unread(23);
    assertEquals("Wrong value read!", 23, tobj.read());
    tobj.unread(13);
    try {
        tobj.unread(13);
        fail("IOException not thrown (ACTUALLY NOT SURE WHETHER IT REALLY MUST BE THROWN!).");
    } catch (IOException e) {
    // expected
    }
}
Also used : IOException(java.io.IOException) PushbackReader(java.io.PushbackReader)

Example 29 with PushbackReader

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

the class OldPushbackReaderTest method test_read_$CII_Exception.

/**
     * java.io.PushbackReader#read(char[], int, int)
     */
public void test_read_$CII_Exception() throws IOException {
    pbr = new PushbackReader(new StringReader(pbString), 10);
    char[] nullCharArray = null;
    char[] charArray = new char[10];
    try {
        pbr.read(nullCharArray, 0, 1);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    try {
        pbr.read(charArray, 0, -1);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        pbr.read(charArray, -1, 0);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        pbr.read(charArray, charArray.length + 1, 0);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        pbr.read(charArray, charArray.length, 1);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        pbr.read(charArray, 1, charArray.length);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        pbr.read(charArray, 0, charArray.length + 1);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    pbr.close();
    try {
        pbr.read(charArray, 0, 1);
        fail("should throw IOException");
    } catch (IOException e) {
    // expected
    }
}
Also used : StringReader(java.io.StringReader) IOException(java.io.IOException) PushbackReader(java.io.PushbackReader)

Example 30 with PushbackReader

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

the class OldPushbackReaderTest method test_unread$C.

/**
     * java.io.PushbackReader#unread(char[])
     */
public void test_unread$C() throws IOException {
    PushbackReader tobj;
    String str2 = "0123456789";
    char[] buf2 = str2.toCharArray();
    char[] readBuf = new char[10];
    tobj = new PushbackReader(underlying, 10);
    tobj.unread(buf2);
    try {
        tobj.unread(buf2);
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
    tobj.read(readBuf);
    assertEquals("Incorrect bytes read", str2, new String(readBuf));
    underlying.throwExceptionOnNextUse = true;
    try {
        tobj.read(buf2);
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
    // Test for method void java.io.PushbackReader.unread(char [])
    try {
        char[] c = new char[5];
        pbr.read(c, 0, 5);
        pbr.unread(c);
        pbr.read(c, 0, 5);
        assertTrue("Failed to unread chars", new String(c).equals(pbString.substring(0, 5)));
    } catch (IOException e) {
        fail("IOException during read test : " + e.getMessage());
    }
}
Also used : IOException(java.io.IOException) 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