Permalink
Browse files

Moved string-input-stream to ring.util.io (see #57)

  • Loading branch information...
1 parent 965c1d6 commit 1e290d3089d8b255446030fe69b2df2a1cbf3a97 @weavejester weavejester committed Mar 19, 2012
Showing with 20 additions and 9 deletions.
  1. +11 −2 ring-core/src/ring/util/io.clj
  2. +5 −7 ring-core/src/ring/util/test.clj
  3. +4 −0 ring-core/test/ring/util/test/io.clj
@@ -1,7 +1,9 @@
(ns ring.util.io
"Utility functions for I/O in Ring."
(:require [clojure.java.io :as io])
- (:import [java.io PipedInputStream PipedOutputStream]))
+ (:import [java.io PipedInputStream
+ PipedOutputStream
+ ByteArrayInputStream]))
(defn piped-input-stream
"Create an input stream from a function that takes an output stream as its
@@ -19,4 +21,11 @@
(try
(func output)
(finally (.close output))))
- input))
+ input))
+
+(defn string-input-stream
+ "Returns a ByteArrayInputStream for the given String."
+ ([^String s]
+ (ByteArrayInputStream. (.getBytes s)))
+ ([^String s encoding]
+ (ByteArrayInputStream. (.getBytes s encoding))))
@@ -1,10 +1,8 @@
(ns ring.util.test
"Utilities for testing Ring components."
- (:import java.io.ByteArrayInputStream))
+ (:require [ring.util.io :as io]))
-(defn string-input-stream
- "Returns a ByteArrayInputStream for the given String."
- ([^String s]
- (ByteArrayInputStream. (.getBytes s)))
- ([^String s encoding]
- (ByteArrayInputStream. (.getBytes s encoding))))
+(def ^{:doc "Returns a ByteArrayInputStream for the given String."
+ :deprecated "1.1"}
+ string-input-stream
+ io/string-input-stream)
@@ -5,4 +5,8 @@
(deftest test-piped-input-stream
(let [stream (piped-input-stream #(spit % "Hello World"))]
+ (is (= (slurp stream) "Hello World"))))
+
+(deftest test-string-input-stream
+ (let [stream (string-input-stream "Hello World")]
(is (= (slurp stream) "Hello World"))))

0 comments on commit 1e290d3

Please sign in to comment.