io管道流 发牌代码
来源:互联网 发布:s7 200 编程电缆 原装 编辑:程序博客网 时间:2024/06/05 06:54
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
class SendCard {
private PipedInputStream ins[];
private PipedOutputStream outs[];
private int datas[][];
public SendCard(int max, int number) throws IOException {
ins=new PipedInputStream[number];
outs=new PipedOutputStream[number];
for(int i=0;i<number;i++){
ins[i]=new PipedInputStream();
outs[i]=new PipedOutputStream(ins[i]);
}
datas=new int[number][max/number];
Sender s=new Sender(max, outs);
s.setPriority(10);
s.start();
for(int i=0;i<number;i++){
new Thread(new Receiver(datas[i],ins[i])).start();
}
}
private void print() {
for(int i=0;i<datas.length;i++){
for(int j=0;j<datas[i].length;j++){
System.out.print(datas[i][j]+" ");
}
System.out.println();
}
}
public static void main(String[] args) {
try {
SendCard sc=new SendCard(52,4);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
sc.print();
} catch (IOException e) {
e.printStackTrace();
}
}
}
package cn.hncu.io2;
import java.io.IOException;
import java.io.PipedOutputStream;
import java.util.Date;
import java.util.Random;
public class Sender extends Thread{
int k=0;
private int max;
private PipedOutputStream outs[];
public Sender(int max, PipedOutputStream[] outs) {
this.max = max;
this.outs = outs;
}
public void run(){
int value=1;
int temp[]=new int[max];
for (int i = 0; i < temp.length; i++) {
temp[i]=i+1;
}
Random r=new Random(new Date().getTime());
for (int i = 0; i < temp.length; i++) {
int n = r.nextInt(max);
temp[i]=temp[i]^temp[n];
temp[n]=temp[i]^temp[n];
temp[i]=temp[i]^temp[n];
}
try {
while(value<=max){
for(int i=0;i<outs.length;i++){
outs[i].write(temp[k++]);
value++;
}
}
for(int i=0;i<outs.length;i++){
outs[i].close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
package cn.hncu.io2;
import java.io.IOException;
import java.io.PipedInputStream;
public class Receiver implements Runnable {
private int data[];
private PipedInputStream in;
public Receiver(int[] data, PipedInputStream in) {
this.data = data;
this.in = in;
}
@Override
public void run() {
int i=0;
try {
int value=in.read();//读取一个字节
while(value!=-1){
data[i++]=value;
value =in.read();
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
- io管道流 发牌代码
- IO流(管道流)
- IO流--管道流
- JAVA IO-管道流
- IO-管道流
- Java IO 管道流
- IO 流之管道流
- IO之管道通信流
- Java IO _管道流
- java IO之管道流
- Java发牌游戏代码
- 随机发牌器-代码
- IO流之管道流类
- JAVA IO流(管道流)
- 黑马程序员-IO(管道流、切割流)
- java笔记-IO流-管道流
- 【java编程】IO流之管道流
- io流-多线程连接管道流
- Java Web 案例1 -- IO,JDBC
- java中线程的使用(未完)
- innodb_buffer_pool特性和参数调整学习
- android Touch事件
- Servlet3.0学习总结(一)——使用注解标注Servlet
- io管道流 发牌代码
- iOS环信3.0集成 (三)单聊集成
- 表格排序——jQuery插件tablesorter的使用
- 自定义View_加载.gif图片
- MySQL解压版安装及编码设置
- 常用linux命令
- CPP 6th——类(8)
- HDU 1056 HangOver 模拟 水题
- android api兼容/被加 的level 查询