From 1e290d3089d8b255446030fe69b2df2a1cbf3a97 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Mon, 19 Mar 2012 19:30:18 +0000 Subject: [PATCH] Moved string-input-stream to ring.util.io (see #57) --- ring-core/src/ring/util/io.clj | 13 +++++++++++-- ring-core/src/ring/util/test.clj | 12 +++++------- ring-core/test/ring/util/test/io.clj | 4 ++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/ring-core/src/ring/util/io.clj b/ring-core/src/ring/util/io.clj index 07a3011..5afc6d4 100644 --- a/ring-core/src/ring/util/io.clj +++ b/ring-core/src/ring/util/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)) \ No newline at end of file + input)) + +(defn string-input-stream + "Returns a ByteArrayInputStream for the given String." + ([^String s] + (ByteArrayInputStream. (.getBytes s))) + ([^String s encoding] + (ByteArrayInputStream. (.getBytes s encoding)))) diff --git a/ring-core/src/ring/util/test.clj b/ring-core/src/ring/util/test.clj index de41b78..5826d0a 100644 --- a/ring-core/src/ring/util/test.clj +++ b/ring-core/src/ring/util/test.clj @@ -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) diff --git a/ring-core/test/ring/util/test/io.clj b/ring-core/test/ring/util/test/io.clj index 2306cba..9869e62 100644 --- a/ring-core/test/ring/util/test/io.clj +++ b/ring-core/test/ring/util/test/io.clj @@ -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")))) \ No newline at end of file