Skip to content

Instantly share code, notes, and snippets.

@clonekim
Created December 20, 2018 04:33
Show Gist options
  • Save clonekim/fbc1754498a4eeff6cb4682dd24a194e to your computer and use it in GitHub Desktop.
Save clonekim/fbc1754498a4eeff6cb4682dd24a194e to your computer and use it in GitHub Desktop.
clojure pipestream
(let [in (java.io.PipedInputStream.)
out (java.io.PipedOutputStream.)
buf (java.io.BufferedWriter. (java.io.OutputStreamWriter. out))]
(.connect out in)
(doto buf
(.write "abdf")
(.write "abadfdf")
(.flush))
(with-open [w (clojure.java.io/writer "stuff.txt")]
(loop [b (.read in)]
(when (< 0 (.available in))
(.write w b)
(recur (.read in))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment