Code example for PipedOutputStream

Methods: flush, write

0
            // Expected. 
        } 
    } 
 
    public void test_flush() throws Exception { 
        out = new PipedOutputStream();
        rt = new Thread(reader = new PReader(out));
        rt.start();
        out.write(testString.getBytes(), 0, 10);
        assertTrue("Test 1: Bytes have been written before flush.", reader.available() != 0);
        out.flush();
        assertEquals("Test 2: Flush failed. ",
                testString.substring(0, 10), reader.read(10));
    } 
 
    public void test_write$BII() throws IOException { 
        out = new PipedOutputStream();
 
        try { 
            out.write(testString.getBytes(), 0, 5);
            fail("Test 1: IOException expected.");