Search in sources :

Example 41 with CharArrayReader

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

the class BufferedReaderTest method test_read.

/**
	 * @tests java.io.BufferedReader#read()
	 */
public void test_read() throws IOException {
    // Test for method int java.io.BufferedReader.read()
    try {
        br = new BufferedReader(new Support_StringReader(testString));
        int r = br.read();
        assertTrue("Char read improperly", testString.charAt(0) == r);
        br = new BufferedReader(new Support_StringReader(new String(new char[] { '蝥' })));
        assertTrue("Wrong double byte character", br.read() == '蝥');
    } catch (java.io.IOException e) {
        fail("Exception during read test");
    }
    char[] chars = new char[256];
    for (int i = 0; i < 256; i++) chars[i] = (char) i;
    Reader in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
    try {
        // Fill the
        assertEquals("Wrong initial char", 0, in.read());
        // buffer
        char[] buf = new char[14];
        // Read greater than the buffer
        in.read(buf, 0, 14);
        assertTrue("Wrong block read data", new String(buf).equals(new String(chars, 1, 14)));
        // Check next byte
        assertEquals("Wrong chars", 15, in.read());
    } catch (IOException e) {
        fail("Exception during read test 2:" + e);
    }
    // regression test for HARMONY-841
    assertTrue(new BufferedReader(new CharArrayReader(new char[5], 1, 0), 2).read() == -1);
}
Also used : CharArrayReader(java.io.CharArrayReader) BufferedReader(java.io.BufferedReader) PipedReader(java.io.PipedReader) Support_StringReader(tests.support.Support_StringReader) CharArrayReader(java.io.CharArrayReader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) IOException(java.io.IOException) Support_StringReader(tests.support.Support_StringReader)

Example 42 with CharArrayReader

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

the class OldBufferedReaderTest method test_read.

public void test_read() throws IOException {
    Support_ASimpleReader ssr = new Support_ASimpleReader(true);
    try {
        br = new BufferedReader(new Support_StringReader(testString));
        int r = br.read();
        assertTrue("Char read improperly", testString.charAt(0) == r);
        br = new BufferedReader(new Support_StringReader(new String(new char[] { '蝥' })));
        assertTrue("Wrong double byte character", br.read() == '蝥');
    } catch (java.io.IOException e) {
        fail("Exception during read test");
    }
    char[] chars = new char[256];
    for (int i = 0; i < 256; i++) chars[i] = (char) i;
    Reader in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
    try {
        // Fill the
        assertEquals("Wrong initial char", 0, in.read());
        // buffer
        char[] buf = new char[14];
        // Read greater than the buffer
        in.read(buf, 0, 14);
        assertTrue("Wrong block read data", new String(buf).equals(new String(chars, 1, 14)));
        // Check next byte
        assertEquals("Wrong chars", 15, in.read());
    } catch (IOException e) {
        fail("Exception during read test 2:" + e);
    }
    // regression test for HARMONY-841
    assertTrue(new BufferedReader(new CharArrayReader(new char[5], 1, 0), 2).read() == -1);
    br.close();
    br = new BufferedReader(ssr);
    try {
        br.read();
        fail("IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    // Avoid IOException in tearDown().
    ssr.throwExceptionOnNextUse = false;
}
Also used : CharArrayReader(java.io.CharArrayReader) Support_ASimpleReader(tests.support.Support_ASimpleReader) BufferedReader(java.io.BufferedReader) PipedReader(java.io.PipedReader) Support_ASimpleReader(tests.support.Support_ASimpleReader) Support_StringReader(tests.support.Support_StringReader) CharArrayReader(java.io.CharArrayReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) ThrowingReader(tests.support.ThrowingReader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IOException(java.io.IOException) Support_StringReader(tests.support.Support_StringReader)

Example 43 with CharArrayReader

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

the class OldCharArrayReaderTest method test_ready.

public void test_ready() {
    // Test for method boolean java.io.CharArrayReader.ready()
    cr = new CharArrayReader(hw);
    boolean expectException = false;
    try {
        assertTrue("ready returned false", cr.ready());
        cr.skip(1000);
        assertTrue("ready returned true", !cr.ready());
        cr.close();
        expectException = true;
        cr.ready();
        fail("No exception 1");
    } catch (IOException e) {
        if (!expectException)
            fail("Unexpected: " + e);
    }
    try {
        cr = new CharArrayReader(hw);
        cr.close();
        cr.ready();
        fail("No exception 2");
    } catch (IOException e) {
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException)

Example 44 with CharArrayReader

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

the class OldCharArrayReaderTest method test_read.

/**
     * java.io.CharArrayReader#read()
     */
public void test_read() throws IOException {
    cr = new CharArrayReader(hw);
    assertEquals("Test 1: Read returned incorrect char;", 'H', cr.read());
    cr = new CharArrayReader(new char[] { '蝥' });
    assertTrue("Test 2: Incorrect double byte char;", cr.read() == '蝥');
    cr.close();
    try {
        cr.read();
        fail("Test 3: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException)

Example 45 with CharArrayReader

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

the class OldCharArrayReaderTest method test_close.

/**
     * java.io.CharArrayReader#close()
     */
public void test_close() {
    cr = new CharArrayReader(hw);
    cr.close();
    try {
        cr.read();
        fail("Failed to throw exception on read from closed stream");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException)

Aggregations

CharArrayReader (java.io.CharArrayReader)64 IOException (java.io.IOException)37 BufferedReader (java.io.BufferedReader)16 Reader (java.io.Reader)13 InputStreamReader (java.io.InputStreamReader)8 File (java.io.File)6 FileReader (java.io.FileReader)6 StringReader (java.io.StringReader)6 BufferedWriter (java.io.BufferedWriter)5 CharArrayWriter (java.io.CharArrayWriter)5 FileWriter (java.io.FileWriter)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 PipedReader (java.io.PipedReader)4 Signature (java.security.Signature)4 DataFormatException (java.util.zip.DataFormatException)4 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)4 PEMParser (org.bouncycastle.openssl.PEMParser)4 JcaPEMKeyConverter (org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter)4 Document (org.w3c.dom.Document)4 InputStream (java.io.InputStream)3