R
Ryan Stewart
Is there something about wrapping PipedInputStreams and/or
PipedOutputStreams? Specifically, I'm trying to wrap them with
ObjectInputStreams and ObjectOutputStreams. With this code:
ObjectOutputStream oos = new ObjectOutputStream(pipeOut);
ObjectInputStream ois = new ObjectInputStream(pipeIn);
The first line appears to work, but code execution stops at the second line.
No exceptions or anything. It just stops.
Here's an executable example in two public classes. The first class creates
an piped in and out and instantiates the second class, which connects to
them. The first class sends one byte on pipeOut then pauses and listens for
a reply. The second class listens for the byte from the first class,
multiplies it by five, and sends it back. It all works as expected. But if
you put in the Object streams there, it screws everything up. Anyone know
why?
// First class
import java.io.*;
public class TestOut {
public static void main(String[] args) {
try {
PipedInputStream pipeIn = new PipedInputStream();
PipedOutputStream pipeOut = new PipedOutputStream();
TestIn ti = new TestIn(pipeIn, pipeOut);
System.out.println("Wrapping...");
//ObjectOutputStream oos = new ObjectOutputStream(pipeOut);
//ObjectInputStream ois = new ObjectInputStream(pipeIn);
System.out.println("Done wrapping.");
ti.start();
pipeOut.write(5);
Thread.sleep(100);
int result = pipeIn.read();
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
// Second class
import java.io.*;
public class TestIn extends Thread {
PipedInputStream pipeIn;
PipedOutputStream pipeOut;
public TestIn(PipedInputStream pipeIn, PipedOutputStream pipeOut) {
try {
this.pipeIn = new PipedInputStream(pipeOut);
this.pipeOut = new PipedOutputStream(pipeIn);
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() {
try {
System.out.println("Listening");
int data = pipeIn.read();
pipeOut.write(data * 5);
} catch (Exception e) {
e.printStackTrace();
}
}
}
PipedOutputStreams? Specifically, I'm trying to wrap them with
ObjectInputStreams and ObjectOutputStreams. With this code:
ObjectOutputStream oos = new ObjectOutputStream(pipeOut);
ObjectInputStream ois = new ObjectInputStream(pipeIn);
The first line appears to work, but code execution stops at the second line.
No exceptions or anything. It just stops.
Here's an executable example in two public classes. The first class creates
an piped in and out and instantiates the second class, which connects to
them. The first class sends one byte on pipeOut then pauses and listens for
a reply. The second class listens for the byte from the first class,
multiplies it by five, and sends it back. It all works as expected. But if
you put in the Object streams there, it screws everything up. Anyone know
why?
// First class
import java.io.*;
public class TestOut {
public static void main(String[] args) {
try {
PipedInputStream pipeIn = new PipedInputStream();
PipedOutputStream pipeOut = new PipedOutputStream();
TestIn ti = new TestIn(pipeIn, pipeOut);
System.out.println("Wrapping...");
//ObjectOutputStream oos = new ObjectOutputStream(pipeOut);
//ObjectInputStream ois = new ObjectInputStream(pipeIn);
System.out.println("Done wrapping.");
ti.start();
pipeOut.write(5);
Thread.sleep(100);
int result = pipeIn.read();
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
// Second class
import java.io.*;
public class TestIn extends Thread {
PipedInputStream pipeIn;
PipedOutputStream pipeOut;
public TestIn(PipedInputStream pipeIn, PipedOutputStream pipeOut) {
try {
this.pipeIn = new PipedInputStream(pipeOut);
this.pipeOut = new PipedOutputStream(pipeIn);
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() {
try {
System.out.println("Listening");
int data = pipeIn.read();
pipeOut.write(data * 5);
} catch (Exception e) {
e.printStackTrace();
}
}
}