zoukankan      html  css  js  c++  java
  • JAVA_线程间流的通信

    package com.kk.review;

    import java.io.IOException;
    import java.io.PipedInputStream;
    import java.io.PipedOutputStream;

    public class PipedStream {
    public static void main(String[] args) {
    try{
    PipedInputStream pis=new PipedInputStream();
    PipedOutputStream pos=new PipedOutputStream();
    pis.connect(pos);
    new Producer(pos).start();
    new Consumer(pis).start();
    }catch(IOException ioe){
    ioe.printStackTrace();
    }

    }
    }

    class Producer extends Thread {
    PipedOutputStream pos;

    public Producer(PipedOutputStream pos) {
    this.pos = pos;
    }

    public void run(){
    try{
    pos.write("hello".getBytes());
    pos.close();
    }catch(IOException ioe){
    ioe.printStackTrace();
    }
    }
    }

    class Consumer extends Thread{
    PipedInputStream pis;
    public Consumer(PipedInputStream pis) {
    this.pis=pis;
    }
    public void run(){
    try{
    byte []buf=new byte[100];
    int len=pis.read(buf);
    String str=new String(buf,0,len);
    System.out.println(str);
    pis.close();
    }catch(IOException ioe){
    ioe.printStackTrace();
    }
    }
    }



  • 相关阅读:
    windows权限维持
    pocsuite3检测工具 编写poc
    php异或免杀
    python 多线程ftp爆破
    python ip查询 whois查询 # CDN查询# 子域名查询# 端口扫描
    python src批量爬取
    qykcms 审计
    dedecms审计
    EasySNS 审计
    zzcms审计
  • 原文地址:https://www.cnblogs.com/BigIdiot/p/2281973.html
Copyright © 2011-2022 走看看