Skip to content

Instantly share code, notes, and snippets.

@viksit
Created June 19, 2010 08:29
Show Gist options
  • Save viksit/444710 to your computer and use it in GitHub Desktop.
Save viksit/444710 to your computer and use it in GitHub Desktop.
(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