Java 8 PipedReader - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 PipedReader class.

This code example shows how to use the following methods:connect, read, sleep
     * @tests java.io.PipedReader#connect(java.io.PipedWriter) 
     */ 
    public void test_connectLjava_io_PipedWriter() throws Exception { 
        char[] c = null;
 
        preader = new PipedReader();
        t = new Thread(pwriter = new PWriter(), "");
        preader.connect(pwriter.pw);
        t.start();
        Thread.sleep(500); // Allow writer to start
        c = new char[11];
        preader.read(c, 0, 11);
 
        assertEquals("Read incorrect chars", "Hello World", new String(c));
        try { 
            preader.connect(pwriter.pw);
            fail("Failed to throw exception connecting to pre-connected reader");
        } catch (IOException e) {
            // Expected 
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:connect, read, sleep
     * @tests java.io.PipedReader#connect(java.io.PipedWriter) 
     */ 
    public void test_connectLjava_io_PipedWriter() throws Exception { 
        char[] c = null;
 
        preader = new PipedReader();
        t = new Thread(pwriter = new PWriter(), "");
        preader.connect(pwriter.pw);
        t.start();
        Thread.sleep(500); // Allow writer to start
        c = new char[11];
        preader.read(c, 0, 11);
 
        assertEquals("Read incorrect chars", "Hello World", new String(c));
        try { 
            preader.connect(pwriter.pw);
            fail("Failed to throw exception connecting to pre-connected reader");
        } catch (IOException e) {
            // Expected 
        } 
    } 
5
CodeRank
This code example shows how to use the following methods:close, read, sleep
    /** 
     * @tests java.io.PipedReader#close() 
     */ 
    public void test_close() throws Exception { 
        char[] c = null;
        preader = new PipedReader();
        t = new Thread(new PWriter(preader), "");
        t.start();
        Thread.sleep(500); // Allow writer to start
        c = new char[11];
        preader.read(c, 0, 11);
        preader.close();
        assertEquals("Read incorrect chars", "Hello World", new String(c));
    } 
 
    /** 
     * @tests java.io.PipedReader#connect(java.io.PipedWriter) 
     */ 
    public void test_connectLjava_io_PipedWriter() throws Exception { 
        char[] c = null;
5
CodeRank
This code example shows how to use the following methods:read
        testInterruptOutputStream(out);
    } 
 
    public void testInterruptPipedReader() throws Exception {
        PipedWriter writer = new PipedWriter();
        PipedReader reader = new PipedReader(writer);
        testInterruptReader(reader);
    } 
 
    public void testInterruptPipedWriter() throws Exception {
        final PipedWriter writer = new PipedWriter();
        new PipedReader(writer);
        testInterruptWriter(writer);
    } 
 
    public void testInterruptReadablePipeChannel() throws Exception {
        testInterruptReadableChannel(Pipe.open().source());
    } 
 
    public void testInterruptWritablePipeChannel() throws Exception {

5
CodeRank
This code example shows how to use the following methods:close
            fail("should throw IOException");
        } catch (IOException e) {
            // expected 
        } 
    	 
        pr = new PipedReader();
        pw = new PipedWriter(pr);
        pr.close();
	 
        try { 
            pw.flush();
            fail("should throw IOException");
        } catch (IOException e) {
            // expected 
        } 
    } 
 
    /** 
     * @tests java.io.PipedWriter#write(char[], int, int) 
     */ 
5
CodeRank
This code example shows how to use the following methods:close
     * can cause a deadlock. 
     */ 
    public void testGetInfo() throws IOException {
        sysinfo_api_helper sah = new sysinfo_api_helper();
        sah.start();
        PipedReader pipeR = new PipedReader(sah.getPipedWriter());
        BufferedReader br = new BufferedReader(pipeR);
        assertEquals("------------------ Java Information ------------------", 
                     br.readLine());
        br.close();
        pipeR.close();
    } 
 
    /** 
     *  setUp - get a DatabaseMetadata object with which to compare 
     *          database information with what is reported by sysinfo 
     */ 
    public void setUp() throws SQLException {
        dm = getConnection().getMetaData();
    } 
5
CodeRank
This code example shows how to use the following methods:
 
        public char[] buf;
 
        public PReader(PipedWriter pw) {
            try { 
                pr = new PipedReader(pw);
            } catch (IOException e) {
                System.out.println("Exception setting up reader: "
                        + e.toString());
            } 
        } 
 
        public PReader(PipedReader pr) {
            this.pr = pr;
        } 
 
        public void run() { 
            try { 
                while (true) { 
                    Thread.sleep(1000);
4
CodeRank
This code example shows how to use the following methods:
 
	public LiterateHaskellReader(final Reader reader) {
		fInput = new BufferedReader(reader);
		fProcessedOutput = new PipedWriter();
		try { 
			fProcessedInput = new BufferedReader(new PipedReader(fProcessedOutput));
		} catch (IOException e) {
			// should not happen 
			throw new AssertionError();
		} 
	} 
 
	@Override 
	public int read(final char[] cbuf, final  int off, final int len) throws IOException {
		int numCharsNeeded = len - countAlreadyAvailableChars(len);
		unlitStream(numCharsNeeded);
		 
		return fProcessedInput.read(cbuf, off, len);
	} 
 
4
CodeRank
This code example shows how to use the following methods:
 
        private ExecutorService executor;
        private Future<char[]> future;
 
        public Writer create() throws IOException {
            final PipedReader in = new PipedReader();
            PipedWriter out = new PipedWriter(in);
 
            executor = Executors.newSingleThreadExecutor();
            future = executor.submit(new Callable<char[]>() {
                final CharArrayWriter chars = new CharArrayWriter();
                public char[] call() throws Exception { 
                    char[] buffer = new char[256];
                    int count;
                    while ((count = in.read(buffer)) != -1) {
                        chars.write(buffer, 0, count);
                    } 
                    return chars.toCharArray();
                } 
            }); 
4
CodeRank
This code example shows how to use the following methods:
 
        public char[] buf;
 
        public PReader(PipedWriter pw) {
            try { 
                pr = new PipedReader(pw);
            } catch (IOException e) {
                System.out.println("Exception setting up reader: "
                        + e.toString());
            } 
        } 
 
        public PReader(PipedReader pr) {
            this.pr = pr;
        } 
 
        public void run() { 
            try { 
                while (true) { 
                    Thread.sleep(1000);
4
CodeRank
See Code Examples for Java 8 PipedReader Methods: