Created
July 8, 2014 15:01
-
-
Save jafingerhut/1c61ec6b99a7656895e0 to your computer and use it in GitHub Desktop.
Example of reading java.io.InputStream in Clojure
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
(ns inputstream.core | |
(:require [clojure.java.io :as io])) | |
(defn read-is [^java.io.InputStream is] | |
(let [bufsize 8192 | |
buf (byte-array bufsize)] | |
(loop [total-len 0] | |
(let [n (.read is buf)] | |
(cond | |
(pos? n) (do | |
;; process n bytes in buf here | |
(println "Read" n " bytes") | |
(recur (+ total-len n))) | |
:else total-len))))) ;; or whatever ret value you want | |
(defn proc-file [fname] | |
(read-is (io/input-stream fname))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
do you maybe know how can I get sth like this?