Petrus Theron
Petrus Theron

Reputation: 28856

Convert BufferedInputStream to String in Clojure

mock.request is returning the response :body as a BufferedInputStream. I need to print and compare this as a string. How do I convert it?

When I try to pass response as a message to my assertion, I see a raw output, e.g.

(is (= 200 (:status response) (:body response)))
=> #object[java.io.BufferedInputStream 0x211bdf40 java.io.BufferedInputStream@211bdf40]

Related questions are Java-specific.

Upvotes: 10

Views: 3517

Answers (2)

DanLebrero
DanLebrero

Reputation: 8591

I tend to use https://github.com/ztellman/byte-streams:

(convert (:body res) String)

Upvotes: 2

OlegTheCat
OlegTheCat

Reputation: 4513

Just slurp it:

(slurp (:body response))

Upvotes: 17

Related Questions