(piped-input-stream func)
Create an input stream from a function that takes an output stream as its
argument. The function will be executed in a separate thread. The stream
will be automatically closed after the function finishes.
For example:
(piped-input-stream
(fn [ostream]
(spit ostream "Hello")))
Source
(defn piped-input-stream
"Create an input stream from a function that takes an output stream as its
argument. The function will be executed in a separate thread. The stream
will be automatically closed after the function finishes.
For example:
(piped-input-stream
(fn [ostream]
(spit ostream \"Hello\")))"
{:added "1.1"}
[func]
(let [input (PipedInputStream.)
output (PipedOutputStream.)]
(.connect input output)
(future
(try
(func output)
(finally (.close output))))
input))