Created
June 19, 2010 08:29
-
-
Save viksit/444710 to your computer and use it in GitHub Desktop.
This file contains 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 file (File. "/tmp/outfile.dat")) | |
(def dos (-> file java.io.FileOutputStream. java.io.DataOutputStream.)) | |
(defn write-seqs [#^java.io.DataOutputStream dos] | |
(for [i (range 0 10)] | |
(.writeInt dos i))) | |
(write-seqs dos) | |
(def dis (-> file java.io.FileInputStream. java.io.DataInputStream.)) | |
(defn read-seqs [#^java.io.DataInputStream dis] | |
(lazy-seq | |
(try | |
(cons (.readInt dis) (read-seqs dis)) | |
(catch java.io.EOFException e | |
(.close dis))))) | |
(with-open [dis (-> file java.io.FileInputStream. java.io.DataInputStream.)] | |
(let [s (read-seqs dis)] | |
(doseq [f s] | |
(println f)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment