Does compojure automatically closes input-streams ?

33 views
Skip to first unread message

Vagif Verdi

unread,
Jun 25, 2010, 4:13:17 PM6/25/10
to Compojure
compojure 0.3.2
I often set a :body of response to some file stream (InputStream).

Works fine. But lately when reviewing my code i noticed that the only
streams i do not close myself are the ones i pass to compojure
via :body attribute.

So my question is, does compojure close those input streams ? Or could
it be a resource leak ?

James Reeves

unread,
Jun 26, 2010, 6:17:54 AM6/26/10
to Compojure
On Jun 25, 9:13 pm, Vagif Verdi <vagif.ve...@gmail.com> wrote:
> So my question is, does compojure close those input streams ? Or could
> it be a resource leak ?

It closes the body input stream when it's finished with it:

(instance? InputStream body)
(with-open [out (.getOutputStream response)]
(IOUtils/copy body out)
(.close body)
(.flush out))

- James
Reply all
Reply to author
Forward
0 new messages