Search in sources :

Example 31 with Support_OutputStream

use of tests.support.Support_OutputStream in project robovm by robovm.

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 32 with Support_OutputStream

use of tests.support.Support_OutputStream in project robovm by robovm.

the class OldFilterOutputStreamTest method test_write$BII.

public void test_write$BII() throws IOException {
    Support_OutputStream sos = new Support_OutputStream(testLength);
    os = new FilterOutputStream(sos);
    os.write(fileString.getBytes(), 10, testLength - 10);
    bis = new ByteArrayInputStream(sos.toByteArray());
    assertTrue("Test 1: Bytes have not been written.", bis.available() == testLength - 10);
    byte[] wbytes = new byte[testLength - 10];
    bis.read(wbytes);
    assertTrue("Test 2: Incorrect bytes written or read.", fileString.substring(10).equals(new String(wbytes)));
    try {
        // Support_OutputStream throws an IOException if the internal
        // buffer is full, which it should be eventually.
        os.write(fileString.getBytes());
        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 33 with Support_OutputStream

use of tests.support.Support_OutputStream in project robovm by robovm.

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 34 with Support_OutputStream

use of tests.support.Support_OutputStream in project robovm by robovm.

the class OldObjectOutputStreamTest method setUp.

/**
     * Sets up the fixture, for example, open a network connection. This method
     * is called before a test is executed.
     */
protected void setUp() throws Exception {
    super.setUp();
    oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
    oos_ioe = new ObjectOutputStream(sos = new Support_OutputStream());
    sos.setThrowsException(true);
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 35 with Support_OutputStream

use of tests.support.Support_OutputStream in project robovm by robovm.

the class OldOutputStreamWriterTest method test_getEncoding.

public void test_getEncoding() throws IOException {
    OutputStreamWriter writer;
    writer = new OutputStreamWriter(new Support_OutputStream(), "utf-8");
    assertEquals("Test 1: Incorrect encoding returned.", Charset.forName("utf-8"), Charset.forName(writer.getEncoding()));
    writer.close();
    assertNull("Test 2: getEncoding() did not return null for a closed writer.", writer.getEncoding());
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) OutputStreamWriter(java.io.OutputStreamWriter)

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