diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2009-04-09 17:52:32 +0000 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2009-04-09 17:52:32 +0000 |
commit | 9ea45de2be0334513ff4230dcd842a06936bd7ad (patch) | |
tree | 98bc485a03bb4e1405c403d9f19d7eabd89e4182 /src/clojure/contrib/java_utils.clj | |
parent | 19641235676df4355ada6dfd2acb8ce2190642de (diff) |
added Perry Trolard's properties helpers
added tests that use a fixture dir (we should standardize on something here)
Diffstat (limited to 'src/clojure/contrib/java_utils.clj')
-rw-r--r-- | src/clojure/contrib/java_utils.clj | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/clojure/contrib/java_utils.clj b/src/clojure/contrib/java_utils.clj index 097afd9c..c5e120bb 100644 --- a/src/clojure/contrib/java_utils.clj +++ b/src/clojure/contrib/java_utils.clj @@ -29,9 +29,11 @@ ; Stuart Halloway ; Stephen C. Gilardi ; Shawn Hoover +; Perry Trolard (ns clojure.contrib.java-utils - (:import [java.io File])) + (:import [java.io File] + [java.util Properties])) (defmulti relative-path-string "Interpret a String or java.io.File as a relative path string. @@ -100,6 +102,33 @@ (set-system-properties current#))))) +; Not there is no corresponding props->map. Just destructure! +(defn as-properties + "Convert any seq of pairs to a java.utils.Properties instance. + Uses as-str to convert both keys and values into strings." + {:tag Properties} + [m] + (let [p (Properties.)] + (doseq [[k v] m] + (.setProperty p (as-str k) (as-str v))) + p)) + +(defn read-properties + "Read properties from file-able." + [file-able] + (with-open [f (java.io.FileInputStream. (file file-able))] + (doto (Properties.) + (.load f)))) + +(defn write-properties + "Write properties to file-able." + {:tag Properties} + ([m file-able] (write-properties m file-able nil)) + ([m file-able comments] + (with-open [f (java.io.FileOutputStream. (file file-able))] + (doto (as-properties m) + (.store f comments))))) +
\ No newline at end of file |