Search in sources :

Example 26 with Support_OutputStream

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

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

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

the class DigestOutputStreamTest method test_write$BII_7.

/**
 * java.io.DigestOutputStream#write(byte[], int, int)
 */
public void test_write$BII_7() throws IOException, NoSuchAlgorithmException {
    Support_OutputStream sos = new Support_OutputStream(MY_MESSAGE_LEN);
    MessageDigest md = MessageDigest.getInstance(algorithmName[0]);
    DigestOutputStream dos = new DigestOutputStream(sos, md);
    dos.write(myMessage, 0, MY_MESSAGE_LEN);
    try {
        // Support_OutputStream throws an IOException if the internal
        // buffer is full, which it should be now.
        dos.write(myMessage, 0, MY_MESSAGE_LEN);
        fail("Test 1: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) DigestOutputStream(java.security.DigestOutputStream) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest)

Example 28 with Support_OutputStream

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

the class OldBufferedOutputStreamTest method test_write$BII.

public void test_write$BII() throws IOException {
    os = new java.io.BufferedOutputStream(baos = new java.io.ByteArrayOutputStream(), 512);
    os.write(fileString.getBytes(), 0, 500);
    bais = new java.io.ByteArrayInputStream(baos.toByteArray());
    assertEquals("Test 1: Bytes written, not buffered;", 0, bais.available());
    os.flush();
    bais = new java.io.ByteArrayInputStream(baos.toByteArray());
    assertEquals("Test 2: Bytes not written after flush;", 500, bais.available());
    os.write(fileString.getBytes(), 500, 513);
    bais = new java.io.ByteArrayInputStream(baos.toByteArray());
    assertTrue("Test 3: Bytes not written when buffer full.", bais.available() >= 1000);
    byte[] wbytes = new byte[1013];
    bais.read(wbytes, 0, 1013);
    assertTrue("Test 4: Incorrect bytes written or read.", fileString.substring(0, 1013).equals(new String(wbytes, 0, wbytes.length)));
    os.close();
    sos = new Support_OutputStream(true);
    os = new BufferedOutputStream(sos, 10);
    try {
        os.write(fileString.getBytes(), 0, 500);
        fail("Test 5: 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 29 with Support_OutputStream

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

the class OldObjectInputOutputStreamTest method setUp.

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

Example 30 with Support_OutputStream

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

the class OldDataOutputStreamTest method setUp.

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

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