Permalink
Browse files

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

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
View
13 ring-core/src/ring/util/io.clj
@@ -1,7 +1,9 @@
(ns ring.util.io (ns ring.util.io
"Utility functions for I/O in Ring." "Utility functions for I/O in Ring."
(:require [clojure.java.io :as io]) (:require [clojure.java.io :as io])
- (:import [java.io PipedInputStream PipedOutputStream])) + (:import [java.io PipedInputStream
+ PipedOutputStream
+ ByteArrayInputStream]))
(defn piped-input-stream (defn piped-input-stream
"Create an input stream from a function that takes an output stream as its "Create an input stream from a function that takes an output stream as its
@@ -19,4 +21,11 @@
(try (try
(func output) (func output)
(finally (.close 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))))
View
12 ring-core/src/ring/util/test.clj
@@ -1,10 +1,8 @@
(ns ring.util.test (ns ring.util.test
"Utilities for testing Ring components." "Utilities for testing Ring components."
- (:import java.io.ByteArrayInputStream)) + (:require [ring.util.io :as io]))
-(defn string-input-stream +(def ^{:doc "Returns a ByteArrayInputStream for the given String."
- "Returns a ByteArrayInputStream for the given String." + :deprecated "1.1"}
- ([^String s] + string-input-stream
- (ByteArrayInputStream. (.getBytes s))) + io/string-input-stream)
- ([^String s encoding]
- (ByteArrayInputStream. (.getBytes s encoding))))
View
4 ring-core/test/ring/util/test/io.clj
@@ -5,4 +5,8 @@
(deftest test-piped-input-stream (deftest test-piped-input-stream
(let [stream (piped-input-stream #(spit % "Hello World"))] (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")))) (is (= (slurp stream) "Hello World"))))

0 comments on commit 1e290d3

Please sign in to comment.