Hi Herwig,

Thanks for your help.

Herwig Hochleitner writes:
> (defn copy-multi
>   ([input outputs] (copy-multi input outputs (make-array Byte/TYPE 1024)))
>   ([^java.io.InputStream input outputs buffer]
>      (let [size (.read input buffer)]
>        (when (pos? size)
>          (doseq [^java.io.OutputStrean output outputs]
>            (.write output buffer 0 size))
>          (recur input outputs buffer)))))

I tried using the above as follows:

    (defn copy-multi
      ([input outputs] (copy-multi input outputs (make-array Byte/TYPE 1024)))
      ([^java.io.OutputStream input outputs buffer]
         (let [size (.read input buffer)]
           (when (pos? size)
             (doseq [^java.io.OutputStream output outputs]
               (.write output buffer 0 size))
             (recur input outputs buffer)))))

    (defn save-to-disk [file]
      "Saves a temporary file to disk to further analyse it"
      (info "Saving file to disk")
      (let [pipe-in (java.io.PipedInputStream.)
            pipe-out (java.io.PipedOutputStream. pipe-in)]
        (future
          (with-open [in (:body file)
                      file-out (io/output-stream "/tmp/test.txt")]
            (copy-multi in [file-out pipe-out])))
        (update-in file [:body] pipe-in)))

I added `future` so that the pipe-in is read and the pipe-out doesn't
block. However, the program returns before anything is copied. Without
`future` the pipe-in is never read out and the pipe-out blocks. So
either to fast or it never completes.

I'm beginning to think that I'm trying to solve the problem (streaming
one input to file and S3 simultaneously) in a wrong way. Any suggestions?
-- 
Petar Radosevic | @wunki

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to