Skip to content

Commit

Permalink
Rework to use ring's piped-input-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-hull committed Apr 23, 2016
1 parent 3f56b88 commit 7aa5901
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/ring_cede/core.clj
@@ -1,25 +1,23 @@
(ns ring-cede.core
(:require
[ring.util.io :refer [piped-input-stream]]
[ring.util.response :refer [response content-type]]
[compojure.response :refer [Renderable]])
(:import
[javax.imageio ImageIO]
[java.awt.image RenderedImage]
[java.io OutputStream ByteArrayInputStream ByteArrayOutputStream]))
[java.io OutputStream]))

(defn- create-pipe [f pipe-size]
(with-open [out-stream (ByteArrayOutputStream. pipe-size)]
(f out-stream)
(ByteArrayInputStream. (.toByteArray out-stream))))

(defn- png-writer [^RenderedImage img ^OutputStream out]
(ImageIO/write img "png" out))
(ImageIO/write img "png" out)
(.flush out))

(extend-protocol Renderable
RenderedImage
(render [this _]
(->
(partial png-writer this)
(create-pipe 0x20000)
piped-input-stream
response
(content-type "image/png"))))

0 comments on commit 7aa5901

Please sign in to comment.