Skip to content

Instantly share code, notes, and snippets.

@RutledgePaulV
Created May 3, 2020 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RutledgePaulV/9e2acf373521fdd7a118d297ed64feb7 to your computer and use it in GitHub Desktop.
Save RutledgePaulV/9e2acf373521fdd7a118d297ed64feb7 to your computer and use it in GitHub Desktop.
teed-writer.clj
(defn teed-writer [^Writer source ^Writer fork]
(proxy [Writer] []
(write
([c]
(cond
(int? c)
(do (.write source (int c))
(.write fork (int c)))
(string? c)
(do (.write source ^String c)
(.write fork ^String c))
:otherwise
(do (.write source ^chars c)
(.write fork ^chars c))))
([c offset length]
(cond
(string? c)
(do (.write source ^String c (int offset) (int length))
(.write fork ^String c (int offset) (int length)))
:otherwise
(do (.write source ^chars c (int offset) (int length))
(.write fork ^chars c (int offset) (int length))))))
(flush []
(.flush source)
(.flush fork))
(close []
(.close source)
(.close fork))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment