           (. out (write buffer 0 len))
           (recur (. in (read buffer))))))))
 
+(defn glob->regex
+  "Turns a shallow file glob into a regular expression."
+  [s]
+  (re-pattern
+    (.. (escape "\\.+|()[]{}$^" s)
+        (replaceAll "\\*" ".*")
+        (replaceAll "\\?" "."))))
+
+(defn split-path
+  "Splits a path up into its parts."
+  [path]
+  (loop [parts (list) path (file path)]
+    (let [parts (cons (. path (getName)) parts)]
+      (if-let parent (. path (getParent))
+        (recur parts (file parent))
+        parts))))
+ 
+(defn load-file-pattern
+  "Load all files matching a regular expression."
+  [re]
+  (doseq
+    file (grep re (map str (file-seq (file "."))))
+    (load-file file)))
+
+;;;; Mimetypes ;;;;
+
 (def *default-mimetype* "application/octet-stream")
 
 (defn context-mimetype

    (if (. matcher (matches))
      (apply hash-map
        (interleave symbols (rest (re-groups matcher)))))))

(defn update-response
  "Destructively update a HttpServletResponse via a Clojure datatype.


(defmacro GET "Creates a GET resource."
  [route & body]
  `(assoc-route "GET" ~route (resource ~@body)))

(defmacro PUT "Creates a PUT resource."
  [route & body]
  `(assoc-route "POST" ~route (resource ~@body)))

(defmacro POST "Creates a POST resource."
  [route & body]
  `(assoc-route "PUT" ~route (resource ~@body)))

(defmacro DELETE "Creates a DELETE resource."
  [route & body]
  `(assoc-route "DELETE" ~route (resource ~@body)))

;;;; Servlet

(def #^{:doc 
  "A servlet that handles all requests into Compojure. Suitable for
