Search in sources :

Example 1 with Support_OutputStream

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

the class OldBufferedOutputStreamTest method test_flush.

public void test_flush() throws IOException {
    baos = new ByteArrayOutputStream();
    os = new java.io.BufferedOutputStream(baos, 600);
    os.write(fileString.getBytes(), 0, 500);
    os.flush();
    assertEquals("Test 1: Bytes not written after flush;", 500, ((ByteArrayOutputStream) baos).size());
    os.close();
    sos = new Support_OutputStream(true);
    os = new BufferedOutputStream(sos, 10);
    try {
        os.flush();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    // To avoid exception during tearDown().
    sos.setThrowsException(false);
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with Support_OutputStream

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

the class OldBufferedOutputStreamTest method test_writeI.

public void test_writeI() throws IOException {
    baos = new java.io.ByteArrayOutputStream();
    os = new java.io.BufferedOutputStream(baos);
    os.write('t');
    bais = new java.io.ByteArrayInputStream(baos.toByteArray());
    assertEquals("Test 1: Byte written, not buffered;", 0, bais.available());
    os.flush();
    bais = new java.io.ByteArrayInputStream(baos.toByteArray());
    assertEquals("Test 2: Byte not written after flush;", 1, bais.available());
    byte[] wbytes = new byte[1];
    bais.read(wbytes, 0, 1);
    assertEquals("Test 3: Incorrect byte written or read;", 't', wbytes[0]);
    os.close();
    sos = new Support_OutputStream(true);
    os = new BufferedOutputStream(sos, 1);
    os.write('t');
    try {
        // Exception is only thrown when the buffer is flushed.
        os.write('e');
        fail("Test 4: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    // To avoid exception during tearDown().
    sos.setThrowsException(false);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Support_OutputStream(tests.support.Support_OutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 3 with Support_OutputStream

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

the class OldDataInputOutputStreamTest method setUp.

protected void setUp() {
    sos = new Support_OutputStream(256);
    os = new DataOutputStream(sos);
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) DataOutputStream(java.io.DataOutputStream)

Example 4 with Support_OutputStream

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

the class OldByteArrayOutputStreamTest method test_writeToLjava_io_OutputStream.

public void test_writeToLjava_io_OutputStream() throws Exception {
    Support_OutputStream sos = new Support_OutputStream();
    bos = new java.io.ByteArrayOutputStream();
    bos.write(fileString.getBytes(), 0, 10);
    bos.writeTo(sos);
    assertTrue("Test 1: Incorrect string written.", sos.toString().equals(fileString.substring(0, 10)));
    sos.setThrowsException(true);
    try {
        bos.writeTo(sos);
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Support_OutputStream(tests.support.Support_OutputStream) IOException(java.io.IOException)

Example 5 with Support_OutputStream

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

the class OldOutputStreamWriterTest method test_ConstructorLjava_io_OutputStream.

public void test_ConstructorLjava_io_OutputStream() throws IOException {
    OutputStreamWriter writer = null;
    try {
        writer = new OutputStreamWriter(null);
        fail("Test 1: NullPointerException expected.");
    } catch (NullPointerException e) {
    // Expected
    }
    try {
        writer = new OutputStreamWriter(new Support_OutputStream());
    } catch (Exception e) {
        fail("Test 2: Unexpected exception: " + e.getMessage());
    }
    // Test that the default encoding has been used.
    assertEquals("Test 3: Incorrect default encoding used.", Charset.defaultCharset(), Charset.forName(writer.getEncoding()));
    if (writer != null)
        writer.close();
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

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