Search in sources :

Example 6 with FilterOutputStream

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

the class OldFilterOutputStreamTest method test_close.

public void test_close() throws IOException {
    Support_OutputStream sos = new Support_OutputStream();
    os = new FilterOutputStream(sos);
    os.close();
    try {
        os.write(42);
    } catch (java.io.IOException e) {
        fail("Test 1: Unexpected IOException.");
    }
    sos.setThrowsException(true);
    try {
        os.write(42);
        fail("Test 2: IOException expected.");
    } catch (java.io.IOException e) {
    // Expected.
    }
    os = new FilterOutputStream(sos);
    try {
        os.close();
        fail("Test 3: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) IOException(java.io.IOException) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream)

Example 7 with FilterOutputStream

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

the class OldFilterOutputStreamTest method test_flush.

public void test_flush() throws IOException {
    Support_OutputStream sos = new Support_OutputStream(550);
    os = new FilterOutputStream(sos);
    os.write(fileString.getBytes(), 0, 500);
    os.flush();
    assertEquals("Test 1: Bytes not written after flush;", 500, sos.size());
    sos.setThrowsException(true);
    try {
        os.flush();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    sos.setThrowsException(false);
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream)

Example 8 with FilterOutputStream

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

the class OldFilterOutputStreamTest method test_ConstructorLjava_io_OutputStream.

public void test_ConstructorLjava_io_OutputStream() {
    // Test for method java.io.FilterOutputStream(java.io.OutputStream)
    try {
        bos = new ByteArrayOutputStream();
        os = new FilterOutputStream(bos);
        os.write('t');
    } catch (java.io.IOException e) {
        fail("Constructor test failed : " + e.getMessage());
    }
}
Also used : IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FilterOutputStream(java.io.FilterOutputStream)

Example 9 with FilterOutputStream

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

the class OldFilterOutputStreamTest method test_close.

public void test_close() throws IOException {
    Support_OutputStream sos = new Support_OutputStream();
    os = new FilterOutputStream(sos);
    os.close();
    try {
        os.write(42);
    } catch (java.io.IOException e) {
        fail("Test 1: Unexpected IOException.");
    }
    sos.setThrowsException(true);
    try {
        os.write(42);
        fail("Test 2: IOException expected.");
    } catch (java.io.IOException e) {
    // Expected.
    }
    os = new FilterOutputStream(sos);
    try {
        os.close();
        fail("Test 3: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) IOException(java.io.IOException) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream)

Example 10 with FilterOutputStream

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

the class OldFilterOutputStreamTest method test_write$B.

public void test_write$B() throws IOException {
    Support_OutputStream sos = new Support_OutputStream(testLength);
    os = new FilterOutputStream(sos);
    os.write(fileString.getBytes());
    bis = new ByteArrayInputStream(sos.toByteArray());
    assertTrue("Test 1: Bytes have not been written.", bis.available() == testLength);
    byte[] wbytes = new byte[testLength];
    bis.read(wbytes, 0, testLength);
    assertTrue("Test 2: Incorrect bytes written or read.", fileString.equals(new String(wbytes)));
    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)

Aggregations

FilterOutputStream (java.io.FilterOutputStream)34 IOException (java.io.IOException)25 Support_OutputStream (tests.support.Support_OutputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 FileOutputStream (java.io.FileOutputStream)6 OutputStream (java.io.OutputStream)6 InputStream (java.io.InputStream)4 DataOutputStream (java.io.DataOutputStream)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FilterInputStream (java.io.FilterInputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Test (org.junit.Test)3 ByteSink (com.google.common.io.ByteSink)2 BufferedOutputStream (java.io.BufferedOutputStream)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 Writer (java.io.Writer)2