Created
June 21, 2014 20:54
-
-
Save chrisguitarguy/cea752aeab32884151af to your computer and use it in GitHub Desktop.
Read from an input stream until a CRLF.
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
(defn read-line-crlf [instream] | |
(loop [sb (StringBuilder.) has-cr false] | |
(let [byt (.read instream)] | |
(when (= -1 byt) | |
(throw (java.io.IOException. "Unexpected end of input"))) | |
(let [chr (char byt)] | |
(if (and has-cr (= \newline chr)) | |
(.substring sb 0 (- (.length sb) 1)) | |
(recur | |
(.append sb chr) | |
(if (= \return chr) true false))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment