Last active
March 1, 2017 16:01
-
-
Save ku1ik/e712cfae1383d4dee6aa12576a66dd01 to your computer and use it in GitHub Desktop.
InputStream wrapper which calls given callback after the stream is closed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns example | |
(:import java.io.FilterInputStream)) | |
(defn cleanup-input-stream | |
"InputStream wrapper which calls given callback after | |
the stream is closed." | |
[is cleanup] | |
(proxy [FilterInputStream] [is] | |
(close [] | |
(proxy-super close) | |
(cleanup)))) | |
(defn input-stream-in-tmp-dir [...] | |
(let [dir (create-tmp-dir) | |
file (generate-file dir) | |
cleanup #(delete-tmp-dir dir)] | |
(cleanup-input-stream (input-stream file) cleanup)) | |
(with-open [is (input-stream-in-tmp-dir ...)] | |
(io/copy is ....)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment