PipedInputStream PipedOutputStream pipeline flow and usage

Note pipeline flow need to use multiple threads

package test;
 
 
import java.io.*;
import java.sql.SQLClientInfoException;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.zip.InflaterInputStream;
 
import javax.annotation.processing.FilerException;
import javax.management.RuntimeErrorException;

import privateclass.Filterby_Name;
import privateclass.Filterby_hidden;
import privateclass.Filterby_java;
import privateclass.MyBufferedReader;
import privateclass.Person;
 
public class Main {
 
    private static final String space_operator = " ";
    Final static Double PI = Private Math.PI;
    Final LINE_SEPARATOR = static String Private the System.getProperty ( "line.separator, and is"); 
	Private Final static int SIZE = 1024 * 1024; 

	/ * 
	 * need to meet pipeline flow multithreaded 
	 * as easily threaded deadlock 
	 * because when in a another would be blocked 
	 * then we must remember that when the pipe is connected 
	 * connect 
	 * / 
    public static void main (String [] args) throws Exception { 

    	the PipedInputStream the PipedInputStream new new PIS = (); 
    	the PipedOutputStream the PipedOutputStream new new POS = (); 
    	pis.connect (POS); 
    	the Thread new new the Thread = T1 (the Input new new (PIS)); 
    	the Thread T2 = the Thread new new (new new the Output (POS)); 
    	t1.start (); 
    	t2.start (); 
    	
    	
    } 

	
} 

class the implements the Input Runnable 
{

	private PipedInputStream pis;
	
	public Input(PipedInputStream pis) {
		super();
		this.pis = pis;
	}
	@Override
	public void run() {
		
		byte buf[] = new byte[1024];
		try {
			pis.read(buf);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String s = new String(buf);
		System.out.println(s);
	}
	
}

class Output implements Runnable
{
	private PipedOutputStream pos;
	
	public Output(PipedOutputStream pos) {
		super();
		this.pos = pos;
	}

	@Override 
	public void RUN () { 
		/ * 
		 * thread to sleep here a while 
		 * you'll find a better link between the observed pipe 
		 * / 
		the try { 
			Thread.sleep (5000); 
		} the catch (InterruptedException E1) { 
			/ / Auto-Generated the TODO the catch Block 
			e1.printStackTrace (); 
		} 
		the try { 
			pos.write ( "I write pipe 2333" .getBytes ()); 
		} the catch (IOException E) { 
			// the TODO Auto-Generated the catch Block 
			E .printStackTrace (); 
		} 
	} 
	
}

  

Guess you like

Origin www.cnblogs.com/WINDZLY/p/11828563.html