Java Pipeline Flow

Source: Internet
Author: User

The main function of pipeline flow can be used for communication between two threads, pipeline output stream Pipeoutputstream and pipeline input stream pipeinputstream. Then connect the two pipes together via Connect.

Import Java.io.pipedinputstream;import Java.io.pipedoutputstream;class Send implements Runnable{private PipedOutputStream pos = Null;public Send () {//TODO auto-generated constructor stubpos = new PipedOutputStream ();} @Overridepublic void Run () {//TODO auto-generated method stubstring str = "Hello world!"; try {pos.write (str.getbytes ());} catch (Exception e) {//Todo:handle exceptione.printstacktrace ();} try {pos.close ();} catch (Exception e) {//Todo:handle exceptione.printstacktrace ();}} Public PipedOutputStream GetPos () {return pos;}}  Class Receive implements runnable{private pipedinputstream pis = null;public Receive () {//TODO auto-generated constructor Stubpis = new PipedInputStream ();} Public PipedInputStream Getpis () {return pis;} @Overridepublic void Run () {//TODO auto-generated method stubbyte[] B = new Byte[1024];int len = 0;try {len = Pis.read (b) ;} catch (Exception e) {//Todo:handle exceptione.printstacktrace ();} try {pis.close ();} catch (Exception e) {//Todo:handle exceptIone.printstacktrace ();} System.out.println (New String (b, 0, Len));}} public class PipeDemo01 {public static void main (string[] args) {//TODO auto-generated method Stubsend s = new Send (); Receive r = new receive (), try {s.getpos (). Connect (R.getpis ()),} catch (Exception e) {//Todo:handle Exceptione.printstack Trace ();} New Thread (s). Start (); new Thread (R). Start ();}}

  

Java Pipeline Flow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.