Search in sources :

Example 36 with CharArrayReader

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

the class OldCharArrayReaderTest method test_markI.

/**
     * java.io.CharArrayReader#mark(int)
     */
public void test_markI() throws IOException {
    cr = new CharArrayReader(hw);
    cr.skip(5L);
    cr.mark(100);
    cr.read();
    cr.reset();
    assertEquals("Test 1: Failed to mark correct position;", 'W', cr.read());
    cr.close();
    try {
        cr.mark(100);
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException)

Example 37 with CharArrayReader

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

the class OldCharArrayReaderTest method test_read$CII.

/**
     * java.io.CharArrayReader#read(char[], int, int)
     */
public void test_read$CII() throws IOException {
    // Test for method int java.io.CharArrayReader.read(char [], int, int)
    char[] c = new char[11];
    cr = new CharArrayReader(hw);
    cr.read(c, 1, 10);
    assertTrue("Test 1: Read returned incorrect chars.", new String(c, 1, 10).equals(new String(hw, 0, 10)));
    // Illegal argument checks.
    try {
        cr.read(null, 1, 0);
        fail("Test 2: NullPointerException expected.");
    } catch (NullPointerException e) {
    // Expected.
    }
    try {
        cr.read(c, -1, 1);
        fail("Test 3: ArrayIndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        cr.read(c, 1, -1);
        fail("Test 4: ArrayIndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        cr.read(c, 1, c.length);
        fail("Test 5: ArrayIndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    cr.close();
    try {
        cr.read(c, 1, 1);
        fail("Test 6: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException)

Example 38 with CharArrayReader

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

the class OldCharArrayReaderTest method test_reset.

/**
     * java.io.CharArrayReader#reset()
     */
public void test_reset() throws IOException {
    cr = new CharArrayReader(hw);
    cr.skip(5L);
    cr.mark(100);
    cr.read();
    cr.reset();
    assertEquals("Test 1: Reset failed to return to marker position.", 'W', cr.read());
    cr.close();
    try {
        cr.reset();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException)

Example 39 with CharArrayReader

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

the class OldCharArrayReaderTest method test_markSupported.

/**
     * java.io.CharArrayReader#markSupported()
     */
public void test_markSupported() {
    cr = new CharArrayReader(hw);
    assertTrue("markSupported returned false", cr.markSupported());
}
Also used : CharArrayReader(java.io.CharArrayReader)

Example 40 with CharArrayReader

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

the class BufferedReaderTest method test_read$CII.

/**
	 * @tests java.io.BufferedReader#read(char[], int, int)
	 */
public void test_read$CII() throws Exception {
    char[] ca = new char[2];
    BufferedReader toRet = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(new byte[0])));
    /* Null buffer should throw NPE even when len == 0 */
    try {
        toRet.read(null, 1, 0);
        fail("null buffer reading zero bytes should throw NPE");
    } catch (NullPointerException e) {
    //expected
    }
    try {
        toRet.close();
    } catch (IOException e) {
        fail("unexpected 1: " + e);
    }
    try {
        toRet.read(null, 1, 0);
        fail("null buffer reading zero bytes on closed stream should throw IOException");
    } catch (IOException e) {
    //expected
    }
    /* Closed reader should throw IOException reading zero bytes */
    try {
        toRet.read(ca, 0, 0);
        fail("Reading zero bytes on a closed reader should not work");
    } catch (IOException e) {
    // expected
    }
    /*
		 * Closed reader should throw IOException in preference to index out of
		 * bounds
		 */
    try {
        // Read should throw IOException before
        // ArrayIndexOutOfBoundException
        toRet.read(ca, 1, 5);
        fail("IOException should have been thrown");
    } catch (IOException e) {
    // expected
    }
    // Test to ensure that a drained stream returns 0 at EOF
    toRet = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(new byte[2])));
    try {
        assertEquals("Emptying the reader should return two bytes", 2, toRet.read(ca, 0, 2));
        assertEquals("EOF on a reader should be -1", -1, toRet.read(ca, 0, 2));
        assertEquals("Reading zero bytes at EOF should work", 0, toRet.read(ca, 0, 0));
    } catch (IOException ex) {
        fail("Unexpected IOException : " + ex.getLocalizedMessage());
    }
    // Test for method int java.io.BufferedReader.read(char [], int, int)
    try {
        char[] buf = new char[testString.length()];
        br = new BufferedReader(new Support_StringReader(testString));
        br.read(buf, 50, 500);
        assertTrue("Chars read improperly", new String(buf, 50, 500).equals(testString.substring(0, 500)));
    } catch (java.io.IOException e) {
        fail("Exception during read test");
    }
    BufferedReader bufin = new BufferedReader(new Reader() {

        int size = 2, pos = 0;

        char[] contents = new char[size];

        public int read() throws IOException {
            if (pos >= size)
                throw new IOException("Read past end of data");
            return contents[pos++];
        }

        public int read(char[] buf, int off, int len) throws IOException {
            if (pos >= size)
                throw new IOException("Read past end of data");
            int toRead = len;
            if (toRead > (size - pos))
                toRead = size - pos;
            System.arraycopy(contents, pos, buf, off, toRead);
            pos += toRead;
            return toRead;
        }

        public boolean ready() throws IOException {
            return size - pos > 0;
        }

        public void close() throws IOException {
        }
    });
    try {
        bufin.read();
        int result = bufin.read(new char[2], 0, 2);
        assertTrue("Incorrect result: " + result, result == 1);
    } catch (IOException e) {
        fail("Unexpected: " + e);
    }
    //regression for HARMONY-831
    try {
        new BufferedReader(new PipedReader(), 9).read(new char[] {}, 7, 0);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }
    // Regression for HARMONY-54
    char[] ch = {};
    BufferedReader reader = new BufferedReader(new CharArrayReader(ch));
    try {
        // Check exception thrown when the reader is open.
        reader.read(null, 1, 0);
        fail("Assert 0: NullPointerException expected");
    } catch (NullPointerException e) {
    // Expected
    }
    // Now check IOException is thrown in preference to
    // NullPointerexception when the reader is closed.
    reader.close();
    try {
        reader.read(null, 1, 0);
        fail("Assert 1: IOException expected");
    } catch (IOException e) {
    // Expected
    }
    try {
        // And check that the IOException is thrown before
        // ArrayIndexOutOfBoundException
        reader.read(ch, 0, 42);
        fail("Assert 2: IOException expected");
    } catch (IOException e) {
    // expected
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) 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) PipedReader(java.io.PipedReader) CharArrayReader(java.io.CharArrayReader) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) Support_StringReader(tests.support.Support_StringReader)

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