Package java.io

Examples of java.io.PipedWriter


    /**
     * @tests java.io.PipedWriter#write(char[],int,int)
     */
    public void test_write_$CII_MultiThread() throws Exception {
        final PipedReader pr = new PipedReader();
        final PipedWriter pw = new PipedWriter();

        // test if writer recognizes dead reader
        pr.connect(pw);

        class WriteRunnable implements Runnable {
            boolean pass = false;

            boolean readerAlive = true;

            public void run() {
                try {
                    pw.write(1);
                    while (readerAlive) {
                    // wait the reader thread dead
                    }
                    try {
                        // should throw exception since reader thread
                        // is now dead
                        char[] buf = new char[10];
                        pw.write(buf, 0, 10);
                    } catch (IOException e) {
                        pass = true;
                    }
                } catch (IOException e) {
                  //ignore
View Full Code Here


     * @tests java.io.PipedWriter#write(int)
     */
    public void test_writeI() throws Exception {
        // Test for method void java.io.PipedWriter.write(int)

        pw = new PipedWriter();
        rdrThread = new Thread(reader = new PReader(pw), "writeI");
        rdrThread.start();
        pw.write(1);
        pw.write(2);
        pw.write(3);
View Full Code Here

    /**
     * @tests java.io.PipedReader#PipedReader(java.io.PipedWriter)
     */
    public void test_ConstructorLjava_io_PipedWriter() throws IOException {
        preader = new PipedReader(new PipedWriter());
    }
View Full Code Here

    /**
     * @tests java.io.PipedReader#read(char[], int, int)
     */
    public void test_read$CII_2() throws IOException {
        // Regression for HARMONY-387
        PipedWriter pw = new PipedWriter();
        PipedReader obj = null;
        try {
            obj = new PipedReader(pw);
            obj.read(new char[0], (int) 0, (int) -1);
            fail("IndexOutOfBoundsException expected");
View Full Code Here

    /**
     * @tests java.io.PipedReader#read(char[], int, int)
     */
    public void test_read$CII_3() throws IOException {
        PipedWriter pw = new PipedWriter();
        PipedReader obj = null;
        try {
            obj = new PipedReader(pw);
            obj.read(new char[0], (int) -1, (int) 0);
            fail("IndexOutOfBoundsException expected");
View Full Code Here

    /**
     * @tests java.io.PipedReader#read(char[], int, int)
     */
    public void test_read$CII_4() throws IOException {
        PipedWriter pw = new PipedWriter();
        PipedReader obj = null;
        try {
            obj = new PipedReader(pw);
            obj.read(new char[0], (int) -1, (int) -1);
            fail("IndexOutOfBoundsException expected");
View Full Code Here

    /**
     * @tests java.io.PipedReader#read(char[], int, int)
     */
    public void test_read_$CII_IOException() throws IOException {
        PipedWriter pw = new PipedWriter();
        PipedReader pr = new PipedReader(pw);
        char[] buf = null;
        pr.close();
        try {
            pr.read(buf, 0, 10);
            fail("Should throws IOException"); //$NON-NLS-1$
        } catch (IOException e) {
            // expected
        } finally {
            pw = null;
            pr = null;
        }

        pr = new PipedReader();
        buf = null;
        pr.close();
        try {
            pr.read(buf, 0, 10);
            fail("Should throws IOException"); //$NON-NLS-1$
        } catch (IOException e) {
            // expected
        } finally {
            pr = null;
        }

        pw = new PipedWriter();
        pr = new PipedReader(pw);
        buf = new char[10];
        pr.close();
        try {
            pr.read(buf, -1, 0);
            fail("Should throws IOException"); //$NON-NLS-1$
        } catch (IOException e) {
            // expected
        } finally {
            pw = null;
            pr = null;
        }

        pw = new PipedWriter();
        pr = new PipedReader(pw);
        buf = new char[10];
        pr.close();
        try {
            pr.read(buf, 0, -1);
            fail("Should throws IOException"); //$NON-NLS-1$
        } catch (IOException e) {
            // expected
        } finally {
            pw = null;
            pr = null;
        }

        pw = new PipedWriter();
        pr = new PipedReader(pw);
        buf = new char[10];
        pr.close();
        try {
            pr.read(buf, 1, 10);
            fail("Should throws IOException"); //$NON-NLS-1$
        } catch (IOException e) {
            // expected
        } finally {
            pw = null;
            pr = null;
        }

        pw = new PipedWriter();
        pr = new PipedReader(pw);
        pr.close();
        try {
            pr.read(new char[0], -1, -1);
            fail("should throw IOException"); //$NON-NLS-1$
        } catch (IOException e) {
            // expected
        } finally {
            pw = null;
            pr = null;
        }

        pw = new PipedWriter();
        pr = new PipedReader(pw);
        pr.close();
        try {
            pr.read(null, 0, 1);
            fail("should throw IOException"); //$NON-NLS-1$
        } catch (IOException e) {
            // expected
        } finally {
            pw = null;
            pr = null;
        }

        pw = new PipedWriter();
        pr = new PipedReader(pw);
        try {
            pr.read(null, -1, 1);
            fail("should throw IndexOutOfBoundsException"); //$NON-NLS-1$
        } catch (IndexOutOfBoundsException e) {
            // expected
        } finally {
            pw = null;
            pr = null;
        }

        pw = new PipedWriter();
        pr = new PipedReader(pw);
        try {
            pr.read(null, 0, -1);
            fail("should throw NullPointerException"); //$NON-NLS-1$
        } catch (NullPointerException e) {
            // expected
        } finally {
            pw = null;
            pr = null;
        }

        pw = new PipedWriter();
        pr = new PipedReader(pw);
        try {
            pr.read(new char[10], 11, 0);
            fail("should throw IndexOutOfBoundsException"); //$NON-NLS-1$
        } catch (IndexOutOfBoundsException e) {
            // expected
        } finally {
            pw = null;
            pr = null;
        }

        pw = new PipedWriter();
        pr = new PipedReader(pw);
        try {
            pr.read(null, 1, 0);
            fail("should throw NullPointerException"); //$NON-NLS-1$
        } catch (NullPointerException e) {
View Full Code Here

    static class PWriter implements Runnable {
        public PipedWriter pw;

        public PWriter(PipedReader reader) {
            try {
                pw = new PipedWriter(reader);
            } catch (Exception e) {
                System.out.println("Couldn't create writer");
            }
        }
View Full Code Here

                System.out.println("Couldn't create writer");
            }
        }

        public PWriter() {
            pw = new PipedWriter();
        }
View Full Code Here

    public void test_ConstructorLjava_io_PipedReader() throws Exception {
        // Test for method java.io.PipedWriter(java.io.PipedReader)
        char[] buf = new char[10];
        "HelloWorld".getChars(0, 10, buf, 0);
        PipedReader rd = new PipedReader();
        pw = new PipedWriter(rd);
        rdrThread = new Thread(reader = new PReader(rd), "Constructor(Reader)");
        rdrThread.start();
        pw.write(buf);
        pw.close();
        rdrThread.join(500);
View Full Code Here

TOP

Related Classes of java.io.PipedWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.