I couldn't find anything in core or contrib that wrote out
bytes to a file so I wrote something to do it. Is this
functionality already implemented and I just couldn't find
it? If there isn't anything already, would this be something
good to put in contrib somewhere? Thanks.
(defn write-bytes
"Writes the bytes from the in-stream to the given filename."
[#^java.io.InputStream in-stream #^String filename]
(with-open [out-stream (new FileOutputStream filename)]
(let [buffer (make-array (Byte/TYPE) 4096)]
(loop [bytes (.read in-stream buffer)]
(if (not (neg? bytes))
(do
(.write out-stream buffer 0 bytes)
(recur (.read in-stream buffer))))))))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---