Code example for PipedOutputStream

Methods: closewrite

0
            fail("Test 1: IOException expected.");
        } catch (IOException e) {
            // Expected. 
        } 
 
        out = new PipedOutputStream(new PipedInputStream());
 
        try { 
            out.write(testString.getBytes(), -1, 10);
            fail("Test 2: IndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected. 
        } 
 
        try { 
            out.write(testString.getBytes(), 0, -1);
            fail("Test 3: IndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected. 
        } 
 
        try { 
            out.write(testString.getBytes(), 5, testString.length());
            fail("Test 4: IndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected. 
        } 
 
        out.close();
        out = new PipedOutputStream();
        try { 
            rt = new Thread(reader = new PReader(out));
            rt.start();
            out.write(testString.getBytes(), 0, testString.length());