Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Created June 21, 2014 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisguitarguy/cea752aeab32884151af to your computer and use it in GitHub Desktop.
Save chrisguitarguy/cea752aeab32884151af to your computer and use it in GitHub Desktop.
Read from an input stream until a CRLF.
(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