Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henryw374/3b0b36278fee945b94321df7913ac524 to your computer and use it in GitHub Desktop.
Save henryw374/3b0b36278fee945b94321df7913ac524 to your computer and use it in GitHub Desktop.
clojure fileinputstream delete
(ns delete-on-close-fileinput-stream)
(defn create-fis [^java.io.File f]
(proxy [java.io.FileInputStream] [f]
(close []
(try
(proxy-super close)
(finally
(.delete f))))))
(comment
(spit "a-file" ["hello"])
(.exists (clojure.java.io/file "a-file"))
(slurp "a-file")
(def fis (create-fis (clojure.java.io/file "a-file")))
(slurp fis)
(.exists (clojure.java.io/file "a-file"))
)
@henryw374
Copy link
Author

already supported by:

Path path = Paths.get(filePath);
InputStream fileStream = Files.newInputStream(path, StandardOpenOption.DELETE_ON_CLOSE);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment