Anonymous avatar Anonymous committed 320cb24

Moved json.clj to right place in source tree.

Comments (0)

Files changed (3)

 
     <target name='clojure-repl'>
         <echo file='${basedir}/clojure'>
-            CLOJURE_CP=$JAVA_CLASSPATH:${lib}/*:${src}:${build.classes}
+        CLOJURE_CP=$JAVA_CLASSPATH:${lib}/*:${src}:${build.classes}
         java -cp $CLOJURE_CP jline.ConsoleRunner clojure.lang.Repl
         </echo>
         <chmod file='${basedir}/clojure' perm='+x'/>

src/net/ksojat/json.clj

-;; Copyright (c) 2008 Krešimir Šojat. All rights reserved.  The use and
-;; distribution terms for this software are covered by the Common
-;; Public License 1.0 (http://www.opensource.org/licenses/cpl1.0.php)
-;; which can be found in the file CPL.TXT at the root of this
-;; distribution.  By using this software in any fashion, you are
-;; agreeing to be bound by the terms of this license.  You must not
-;; remove this notice, or any other, from this software.
-;;
-;; Simple wrapper for jackson (http://jackson.codehaus.org/)
-;; library.
-
-(ns net.ksojat.neman.json
-  (:refer-clojure :exclude [read read-string])
-  (:use net.ksojat.neman.core)
-  (:import
-    (org.codehaus.jackson JsonFactory JsonToken)
-    (java.io FileReader FileWriter BufferedWriter StringReader StringWriter)))
-
-;; Helpers
-
-(defn boolean? [n]
-  (instance? Boolean n))
-
-(defn file-reader [pathname]
-  (new FileReader pathname))
-
-(defn file-writer
-  ([pathname]        (FileWriter. pathname))
-  ([pathname append] (FileWriter. pathname append)))
-
-(def *factory* (JsonFactory.))
-
-;;
-;; Reader functions
-;;
-
-(defn reader[source]
-  (.createJsonParser *factory* source))
-
-(defn- current-token [reader]
-  (.getCurrentToken reader))
-
-(defn- next-token [reader]
-  (.nextToken reader))
-
-(defn- get-keyword [reader]
-  (keyword (.getText reader)))
-
-; Forward declaration
-(def read-nested)
-
-(defn- read-array [reader]
-  (next-token reader)
-  (loop [array []]
-    (if (= JsonToken/END_ARRAY (current-token reader))
-        array
-        (recur (conj array (read-nested reader))))))
-
-(defn- read-attr [reader object]
-  (assoc object
-         (get-keyword reader)
-         (do
-           (next-token  reader)
-           (read-nested reader))))
-
-(defn- read-object [reader]
-  (next-token reader)
-  (loop [object {}]
-    (if (= JsonToken/END_OBJECT (current-token reader))
-        object
-        (recur (read-attr reader object)))))
-
-(defn- read-nested [reader]
-  (let [token  (current-token reader)
-        token= #(= token %)
-        value
-          (cond
-            (token= JsonToken/VALUE_NULL)         nil
-            (token= JsonToken/VALUE_FALSE)        false
-            (token= JsonToken/VALUE_TRUE)         true
-            (token= JsonToken/VALUE_NUMBER_FLOAT) (.getDoubleValue reader)
-            (token= JsonToken/VALUE_NUMBER_INT)   (.getIntValue    reader)
-            (token= JsonToken/VALUE_STRING)       (.getText        reader)
-            (token= JsonToken/START_OBJECT)       (read-object reader)
-            (token= JsonToken/START_ARRAY)        (read-array  reader))]
-    (next-token reader)
-    value))
-
-(defn read [reader]
-  (let [node  (next-token reader)
-        node= #(= node %)]
-    (cond
-      (node= JsonToken/START_OBJECT) (read-object reader)
-      (node= JsonToken/START_ARRAY)  (read-array  reader))))
-
-(defn read-stream [s]
-  (let [jr (reader s), res (read jr)]
-    (.close jr) res))
-
-; TODO: Uzmi da koristi read-stream
-(defn read-file [pathname]
-  (let [file-reader (FileReader. pathname)
-        json-reader (reader file-reader)
-        result      (read json-reader)]
-    (.close json-reader)
-    result))
-
-(defn read-string [s]
-  (read-stream (StringReader. s)))
-
-;;
-;; Writer functions
-;;
-
-(defn writer
-  ([target]
-    (doto (.createJsonGenerator *factory* target)
-      (.useDefaultPrettyPrinter)))
-
-  ([target enc]
-    (doto (.createJsonGenerator *factory* target enc)
-      (.useDefaultPrettyPrinter))))
-
-; Forward declaration.
-(def write-nested)
-
-(defn- write-object [writer object]
-  (.writeStartObject writer)
-  (doseq [key (keys object)]
-    (.writeFieldName writer (name key))
-    (write-nested writer (object key)))
-  (.writeEndObject writer))
-
-(defn- write-array [writer vec]
-  (.writeStartArray writer)
-  (doseq [v vec] (write-nested writer v))
-  (.writeEndArray writer))
-
-(defn- write-nested [writer x]
-  (cond
-    (nil?     x) (.writeNull    writer)
-    (string?  x) (.writeString  writer x)
-    (boolean? x) (.writeBoolean writer x)
-    (number?  x) (.writeNumber  writer x)
-    (map?     x) (write-object  writer x)
-    (vector?  x) (write-array   writer x)))
-
-(defn write [writer & body]
-  (let [[x & xs] body]
-    (cond
-      (map?    x) (write-object writer x)
-      (vector? x) (write-array  writer x))
-    (when (seq xs) (recur writer xs))))
-
-(defn write-stream [s data]
-  (let [jw (writer s)]
-    (write jw data)
-    (.flush jw)))
-
-(defn write-file [pathname data]
-  (write-stream (file-writer pathname) data))
-
-(defn append-file [pathname data]
-  (write-stream (file-writer pathname true) data))
-
-(defn write-string [data]
-  (let [sw (StringWriter.)]
-    (write-stream (BufferedWriter. sw) data)
-    (.toString sw)))
-
-

src/net/ksojat/neman/json.clj

+;; Copyright (c) 2008 Krešimir Šojat. All rights reserved.  The use and
+;; distribution terms for this software are covered by the Common
+;; Public License 1.0 (http://www.opensource.org/licenses/cpl1.0.php)
+;; which can be found in the file CPL.TXT at the root of this
+;; distribution.  By using this software in any fashion, you are
+;; agreeing to be bound by the terms of this license.  You must not
+;; remove this notice, or any other, from this software.
+;;
+;; Simple wrapper for jackson (http://jackson.codehaus.org/)
+;; library.
+
+(ns net.ksojat.neman.json
+  (:refer-clojure :exclude [read read-string])
+  (:use net.ksojat.neman.core)
+  (:import
+    (org.codehaus.jackson JsonFactory JsonToken)
+    (java.io FileReader FileWriter BufferedWriter StringReader StringWriter)))
+
+;; Helpers
+
+(defn boolean? [n]
+  (instance? Boolean n))
+
+(defn file-reader [pathname]
+  (new FileReader pathname))
+
+(defn file-writer
+  ([pathname]        (FileWriter. pathname))
+  ([pathname append] (FileWriter. pathname append)))
+
+(def *factory* (JsonFactory.))
+
+;;
+;; Reader functions
+;;
+
+(defn reader[source]
+  (.createJsonParser *factory* source))
+
+(defn- current-token [reader]
+  (.getCurrentToken reader))
+
+(defn- next-token [reader]
+  (.nextToken reader))
+
+(defn- get-keyword [reader]
+  (keyword (.getText reader)))
+
+; Forward declaration
+(def read-nested)
+
+(defn- read-array [reader]
+  (next-token reader)
+  (loop [array []]
+    (if (= JsonToken/END_ARRAY (current-token reader))
+        array
+        (recur (conj array (read-nested reader))))))
+
+(defn- read-attr [reader object]
+  (assoc object
+         (get-keyword reader)
+         (do
+           (next-token  reader)
+           (read-nested reader))))
+
+(defn- read-object [reader]
+  (next-token reader)
+  (loop [object {}]
+    (if (= JsonToken/END_OBJECT (current-token reader))
+        object
+        (recur (read-attr reader object)))))
+
+(defn- read-nested [reader]
+  (let [token  (current-token reader)
+        token= #(= token %)
+        value
+          (cond
+            (token= JsonToken/VALUE_NULL)         nil
+            (token= JsonToken/VALUE_FALSE)        false
+            (token= JsonToken/VALUE_TRUE)         true
+            (token= JsonToken/VALUE_NUMBER_FLOAT) (.getDoubleValue reader)
+            (token= JsonToken/VALUE_NUMBER_INT)   (.getIntValue    reader)
+            (token= JsonToken/VALUE_STRING)       (.getText        reader)
+            (token= JsonToken/START_OBJECT)       (read-object reader)
+            (token= JsonToken/START_ARRAY)        (read-array  reader))]
+    (next-token reader)
+    value))
+
+(defn read [reader]
+  (let [node  (next-token reader)
+        node= #(= node %)]
+    (cond
+      (node= JsonToken/START_OBJECT) (read-object reader)
+      (node= JsonToken/START_ARRAY)  (read-array  reader))))
+
+(defn read-stream [s]
+  (let [jr (reader s), res (read jr)]
+    (.close jr) res))
+
+; TODO: Uzmi da koristi read-stream
+(defn read-file [pathname]
+  (let [file-reader (FileReader. pathname)
+        json-reader (reader file-reader)
+        result      (read json-reader)]
+    (.close json-reader)
+    result))
+
+(defn read-string [s]
+  (read-stream (StringReader. s)))
+
+;;
+;; Writer functions
+;;
+
+(defn writer
+  ([target]
+    (doto (.createJsonGenerator *factory* target)
+      (.useDefaultPrettyPrinter)))
+
+  ([target enc]
+    (doto (.createJsonGenerator *factory* target enc)
+      (.useDefaultPrettyPrinter))))
+
+; Forward declaration.
+(def write-nested)
+
+(defn- write-object [writer object]
+  (.writeStartObject writer)
+  (doseq [key (keys object)]
+    (.writeFieldName writer (name key))
+    (write-nested writer (object key)))
+  (.writeEndObject writer))
+
+(defn- write-array [writer vec]
+  (.writeStartArray writer)
+  (doseq [v vec] (write-nested writer v))
+  (.writeEndArray writer))
+
+(defn- write-nested [writer x]
+  (cond
+    (nil?     x) (.writeNull    writer)
+    (string?  x) (.writeString  writer x)
+    (boolean? x) (.writeBoolean writer x)
+    (number?  x) (.writeNumber  writer x)
+    (map?     x) (write-object  writer x)
+    (vector?  x) (write-array   writer x)))
+
+(defn write [writer & body]
+  (let [[x & xs] body]
+    (cond
+      (map?    x) (write-object writer x)
+      (vector? x) (write-array  writer x))
+    (when (seq xs) (recur writer xs))))
+
+(defn write-stream [s data]
+  (let [jw (writer s)]
+    (write jw data)
+    (.flush jw)))
+
+(defn write-file [pathname data]
+  (write-stream (file-writer pathname) data))
+
+(defn append-file [pathname data]
+  (write-stream (file-writer pathname true) data))
+
+(defn write-string [data]
+  (let [sw (StringWriter.)]
+    (write-stream (BufferedWriter. sw) data)
+    (.toString sw)))
+
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.