<commit_before>(ns overtone.config
  (:use [clojure.contrib.io :only (slurp*)])
  (:import (java.io FileOutputStream FileInputStream)))

;; Provides a simple key/value configuration system with support for automatically
;; persisting to a file on disk.  The config file is serialized clojure code which
;; is easily editable as a text file.

(defonce config*  (ref {}))

(defonce STORE :file)
(defonce store-path* (ref false))
(defn storage [& args] STORE)

;; Store interface:
(defmulti save-config    storage)
(defmulti restore-config storage)

(def F-LOCK :lock)

; Simple flat-file based storage
(defmethod save-config :file
  [path data]
  (locking F-LOCK
      (spit path data)))

(defmethod restore-config :file
  [path]
  (with-open [file (FileInputStream. path)]
    (read-string (slurp* file))))<commit_msg>use duckstreams spit specifically to fix a problem that appears to rear its head with OpenJDK on Linux<commit_after>(ns overtone.config
  (:use [clojure.contrib.io :only (slurp*)])
  (:require [clojure.contrib.duck-streams :as ds])
  (:import (java.io FileOutputStream FileInputStream)))

;; Provides a simple key/value configuration system with support for automatically
;; persisting to a file on disk.  The config file is serialized clojure code which
;; is easily editable as a text file.

(defonce config*  (ref {}))

(defonce STORE :file)
(defonce store-path* (ref false))
(defn storage [& args] STORE)

;; Store interface:
(defmulti save-config    storage)
(defmulti restore-config storage)

(def F-LOCK :lock)

; Simple flat-file based storage
(defmethod save-config :file
  [path data]
  (locking F-LOCK
      (ds/spit path data)))

(defmethod restore-config :file
  [path]
  (with-open [file (FileInputStream. path)]
    (read-string (slurp* file))))
{'fraction_non_alphanumeric': 0.11705120990433314, 'fraction_numerical': 0.0, 'mean_word_length': 4.45398773006135, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7451926', 'n_tokens_mistral': 571, 'n_tokens_neox': 555, 'n_words': 202}