Skip to content

Commit

Permalink
ensure exhausted inputstreams are always closed so we don't hold file…
Browse files Browse the repository at this point in the history
… locks on windows, fixes clojure-clutchgh-2
  • Loading branch information
cemerick committed Dec 13, 2011
1 parent f407bad commit 001eba2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/com/ashafa/clutch.clj
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@
(assoc m (keyword filename)
{:content_type mime
:data (-> data
utils/to-byte-array
; make sure streams are closed so we don't hold locks on files on Windows
(#(with-open [stream %] (utils/to-byte-array stream)))
utils/encode-bytes-to-base64)}))
{})
(hash-map :_attachments))))
Expand Down
3 changes: 2 additions & 1 deletion src/com/ashafa/clutch/http_client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
[^URLConnection connection data]
(with-open [output (.getOutputStream connection)]
(io/copy data output)
(if (instance? InputStream data) (.close ^InputStream data))))
; make sure streams are closed so we don't hold locks on files on Windows
(when (instance? InputStream data) (.close ^InputStream data))))

(defn- get-response
[^HttpURLConnection connection {:keys [read-json-response]}]
Expand Down

0 comments on commit 001eba2

Please sign in to comment.