Search in sources :

Example 46 with Support_OutputStream

use of tests.support.Support_OutputStream in project j2objc by google.

the class OldFilterOutputStreamTest method test_writeI.

public void test_writeI() throws IOException {
    Support_OutputStream sos = new Support_OutputStream(1);
    os = new FilterOutputStream(sos);
    os.write(42);
    bis = new ByteArrayInputStream(sos.toByteArray());
    assertTrue("Test 1: Byte has not been written.", bis.available() == 1);
    assertEquals("Test 2: Incorrect byte written or read;", 42, bis.read());
    try {
        // Support_OutputStream throws an IOException if the internal
        // buffer is full, which it should be now.
        os.write(42);
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream)

Example 47 with Support_OutputStream

use of tests.support.Support_OutputStream in project j2objc by google.

the class OldFilterOutputStreamTest method test_write$BII_Exception.

public void test_write$BII_Exception() throws IOException {
    Support_OutputStream sos = new Support_OutputStream(testLength);
    os = new FilterOutputStream(sos);
    byte[] buf = new byte[10];
    try {
        os.write(buf, -1, 1);
        fail("IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        os.write(buf, 0, -1);
        fail("IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        os.write(buf, 10, 1);
        fail("IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) FilterOutputStream(java.io.FilterOutputStream)

Example 48 with Support_OutputStream

use of tests.support.Support_OutputStream in project j2objc by google.

the class OldObjectOutputStreamTest method test_reset.

public void test_reset() throws Exception {
    String o = "HelloWorld";
    sos = new Support_OutputStream(200);
    oos.close();
    oos = new ObjectOutputStream(sos);
    oos.writeObject(o);
    oos.writeObject(o);
    oos.reset();
    oos.writeObject(o);
    sos.setThrowsException(true);
    try {
        oos.reset();
        fail("Test 1: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    sos.setThrowsException(false);
    ois = new ObjectInputStream(new ByteArrayInputStream(sos.toByteArray()));
    assertEquals("Test 2: Incorrect object read.", o, ois.readObject());
    assertEquals("Test 3: Incorrect object read.", o, ois.readObject());
    assertEquals("Test 4: Incorrect object read.", o, ois.readObject());
    ois.close();
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Support_OutputStream (tests.support.Support_OutputStream)48 IOException (java.io.IOException)30 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 OutputStreamWriter (java.io.OutputStreamWriter)16 FilterOutputStream (java.io.FilterOutputStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)8 BufferedOutputStream (java.io.BufferedOutputStream)6 ObjectOutputStream (java.io.ObjectOutputStream)6 DataOutputStream (java.io.DataOutputStream)4 Charset (java.nio.charset.Charset)4 ObjectInputStream (java.io.ObjectInputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 CharsetEncoder (java.nio.charset.CharsetEncoder)2 DigestOutputStream (java.security.DigestOutputStream)2 MessageDigest (java.security.MessageDigest)2