This commit is contained in:
@@ -3,7 +3,10 @@
|
|||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[clojure.tools.logging :as l]
|
[clojure.tools.logging :as l]
|
||||||
[clojure.java.io :as io])
|
[clojure.java.io :as io])
|
||||||
(:import (java.io FilterInputStream)))
|
(:import (java.io FilterInputStream StringWriter InputStream
|
||||||
|
OutputStream PrintStream ByteArrayOutputStream
|
||||||
|
ByteArrayInputStream)
|
||||||
|
(java.nio.charset StandardCharsets)))
|
||||||
|
|
||||||
(defn deref-with-timeout [process ms]
|
(defn deref-with-timeout [process ms]
|
||||||
(let [p (promise)
|
(let [p (promise)
|
||||||
@@ -20,16 +23,37 @@
|
|||||||
:timed-out-after-milliseconds ms}))
|
:timed-out-after-milliseconds ms}))
|
||||||
@p)))
|
@p)))
|
||||||
|
|
||||||
#_
|
(defn tee-input-stream [sink input-stream]
|
||||||
(defn tee-to-logs [input output]
|
(proxy [FilterInputStream] [input-stream]
|
||||||
(Thread. (fn []
|
(read
|
||||||
(io/copy (l/log-stream :debug)))))
|
([]
|
||||||
|
(let [c (proxy-super read)]
|
||||||
|
(when (not= c -1)
|
||||||
|
(.write sink c))
|
||||||
|
c))
|
||||||
|
([^bytes bs]
|
||||||
|
(let [n (proxy-super read bs)]
|
||||||
|
(when (not= n -1)
|
||||||
|
(.write sink bs 0 n))
|
||||||
|
n))
|
||||||
|
([^bytes bs off len]
|
||||||
|
(let [n (proxy-super read bs off len)]
|
||||||
|
(when (not= n -1)
|
||||||
|
(.write sink bs off n))
|
||||||
|
n)))
|
||||||
|
(close []
|
||||||
|
(try (proxy-super close)
|
||||||
|
(finally (.close sink))))))
|
||||||
|
|
||||||
(defrecord TeeInputStream
|
(comment
|
||||||
[out]
|
(with-open [sink (ByteArrayOutputStream.)
|
||||||
FilterInputStream)
|
out (ByteArrayOutputStream.)
|
||||||
|
in (ByteArrayInputStream. (.getBytes "hello worms"))]
|
||||||
(extend)
|
(io/copy (tee-input-stream sink in) out)
|
||||||
|
(def the-out out)
|
||||||
|
(def the-sink sink)
|
||||||
|
{:out out
|
||||||
|
:sink sink}))
|
||||||
|
|
||||||
(defn invoke [opts & cmd]
|
(defn invoke [opts & cmd]
|
||||||
(l/info (str/join " " (cons "$" cmd)))
|
(l/info (str/join " " (cons "$" cmd)))
|
||||||
|
|||||||
Reference in New Issue
Block a user