Created
January 3, 2013 09:05
-
-
Save tonsky/4442030 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def ^:dynamic chunk-size 17) | |
(defn next-chunk [rdr] | |
(let [buf (char-array chunk-size) | |
s (.read rdr buf)] | |
(when (pos? s) | |
(java.nio.CharBuffer/wrap buf 0 s)))) | |
(defn chunk-seq [rdr] | |
(when-let [chunk (next-chunk rdr)] | |
(cons chunk (lazy-seq (chunk-seq rdr))))) | |
(with-open [rdr (clojure.java.io/reader "/Users/prokopov/.profile")] | |
(doseq [chunk (chunk-seq rdr)] | |
(println "Read" (.remaining chunk) "bytes:" (str chunk)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment