 (ns demogorgon.nh
-  (:import [java.io File FilenameFilter RandomAccessFile]
+  (:import [java.io File FilenameFilter RandomAccessFile ByteArrayOutputStream]
            [org.apache.log4j Logger]
            [java.nio.file FileSystems StandardWatchEventKind])
   (:require [clj-stacktrace.repl :as stacktrace]

                        (race (:race data))
                        (role (:role data))
                        (if (= (:death data) "ascended")
                          " ascended to demigod-good."
                          (format ", left this world %s on level %s, %s."
                                  (zone (:deathdnum data))
                                  (:deathlev data)

               (.debug logger (str "file modified: " fn))
               (let [ra (RandomAccessFile. (str (:un-dir config) fn) "r")]
                 (.seek ra (:length file))
                 (loop [line (read-line-ra ra)]
                   (if line
                     (do 
                       ((:callback file) (:irc @watcher) line)
                       (var-set files (assoc (var-get files)
                                        fn
                                        (assoc (get (var-get files) fn) :length (.getFilePointer ra))))
                       (recur (read-line-ra ra)))))
                 (.close ra)))))
         (.reset key))))))

