1

I need a stream (or something) to which i can write and read using streams, both from program in Java, here is some example:

CustomStream stream = new CustomStream();

BufferedReader reader = new BufferedReader(new InputStreamReader(stream.getInputStream());
PrintWriter pw = new PrintWriter(stream.getOutputStream());

pw.println("Hello");
pw.println("World");

System.out.println(reader.readLine()); //Hello
System.out.println(reader.readLine()); //World

Guess this is pretty retarded example, but is there any way to do it, except implementing all methods from abstract Stream class?

1 Answer 1

3

It sounds like you are looking for a Java Pipe object

http://docs.oracle.com/javase/6/docs/api/java/nio/channels/Pipe.html

The interface is close to what you suggest above. Note that the PipedInputStream and PipedOutputStream classes will make the pipe easier to interface with.

For some applications, the CircularBuffer class may suffice and save on a little typing, but it essentially does the same thing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.