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.
}
}
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.
}
}
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.
}
}
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());
}
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
}
}
Aggregations