Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn create-object-output-stream
- [filename]
- (if (file-exists? filename)
- (-> filename (FileOutputStream. true) AppendingObjectOutputStream.)
- (-> filename (FileOutputStream. true) ObjectOutputStream.)))
- (defn write-to-file
- [file-key, data-map]
- (with-open [obj-out (-> file-key determine-filename create-object-output-stream)]
- (try
- (.writeObject obj-out, (replace-functions-by-symbols data-map))
- (.flush obj-out)
- (catch Throwable t
- (debug-repl "write-to-file")))))
- (defn read-from-file
- [file-key]
- (let [filename (determine-filename file-key)]
- (with-open [obj-in (-> filename FileInputStream. ObjectInputStream.)]
- (loop [result (transient [])]
- (try
- (let [obj (.readObject obj-in)]
- (recur (conj! result obj)))
- (catch EOFException eof
- (persistent! result))
- (catch Throwable t
- (println t)
- (debug-repl "read-from-file")))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement