I have an inputstream that I'd like to get data from a Writer;
basically i'm reading and writing to serialports from Java and i don't have the hardware on me so i'm trying to simulate the data that would be available on these ports.
So I need to connect a Writer to an InputStream, I can then fool my program to think that the InputStream is from the serial port and then simulate what's arriving from teh seral port by writing to my Writer.
I've been trying to figure out the PipedInput/OutputStream classes and tried this sort off a thing:
the effect I was *hoping* for was for something like:
to print out "foo". but off course, this is not working, what am I doing wrong?
How cna I achieve this effect?
I know that pipes are meant for cross-thread stuff, but still
basically i'm reading and writing to serialports from Java and i don't have the hardware on me so i'm trying to simulate the data that would be available on these ports.
So I need to connect a Writer to an InputStream, I can then fool my program to think that the InputStream is from the serial port and then simulate what's arriving from teh seral port by writing to my Writer.
I've been trying to figure out the PipedInput/OutputStream classes and tried this sort off a thing:
PipedInputStream pin = new PipedInputStream();
PipedOutputStream pout = new PipedOutputStream(pin);
writer = new BufferedWriter(new OutputStreamWriter(pout, "US-ASCII"));
the effect I was *hoping* for was for something like:
writer.write("foo");
while(pin.available() > 0)
System.out.print((char) pin.read());
to print out "foo". but off course, this is not working, what am I doing wrong?
How cna I achieve this effect?
I know that pipes are meant for cross-thread stuff, but still