//:PipedStreamTest.java
import java.io.*;public class PipedStreamTest {
public static void main(String[] args) {
Thread t1=new SenderThread();
Thread t2=new ReceiveThread();
PipedOutputStream out=t1.getPipedOutputStream();
PipedInputStream in=t2.getPipedInputStream();
out.connect(in);
t1.start();
t2.start();
}
}
class SenderThread extends Thread {
private PipedOutputStream out=new PipedOutputStream();
PipedOutputStream getPipedOutputStream() {
return out;
}
public void run() {
out.write("www.xmjobs.com".getBytes());
out.close();
}
}
class ReceiveThread extends Thread {
private PipedInputStream in=new PipedInputStream();
PipedInputStream getPipedInputStream() {
return in ;
}
public void run() {
byte[] buf=new byte[1024];
int len=in.read(buf);
System.out.println(new String(buf,0,len));
in.close();
}
}
import java.io.*;public class PipedStreamTest {
public static void main(String[] args) {
Thread t1=new SenderThread();
Thread t2=new ReceiveThread();
PipedOutputStream out=t1.getPipedOutputStream();
PipedInputStream in=t2.getPipedInputStream();
out.connect(in);
t1.start();
t2.start();
}
}
class SenderThread extends Thread {
private PipedOutputStream out=new PipedOutputStream();
PipedOutputStream getPipedOutputStream() {
return out;
}
public void run() {
out.write("www.xmjobs.com".getBytes());
out.close();
}
}
class ReceiveThread extends Thread {
private PipedInputStream in=new PipedInputStream();
PipedInputStream getPipedInputStream() {
return in ;
}
public void run() {
byte[] buf=new byte[1024];
int len=in.read(buf);
System.out.println(new String(buf,0,len));
in.close();
}
}
public static void main(String[] args) {
SenderThread t1 = new SenderThread();
ReceiveThread t2 = new ReceiveThread();
PipedOutputStream out = t1.getPipedOutputStream();
PipedInputStream in = t2.getPipedInputStream();
try {
out.connect(in);
} catch (IOException e) {
e.printStackTrace();
}
t1.start();
t2.start();
}
}class SenderThread extends Thread {
private PipedOutputStream out = new PipedOutputStream(); PipedOutputStream getPipedOutputStream() {
return out;
} public void run() {
try {
out.write("www.xmjobs.com".getBytes());
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}class ReceiveThread extends Thread {
private PipedInputStream in = new PipedInputStream(); PipedInputStream getPipedInputStream() {
return in;
} public void run() {
byte[] buf = new byte[1024];
int len=0;
try {
len = in.read(buf);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(new String(buf, 0, len));
}
}