aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Sierra <mail@stuartsierra.com>2009-11-13 11:58:10 -0500
committerStuart Sierra <mail@stuartsierra.com>2009-11-13 11:58:10 -0500
commit2ae8ff46d348522efe9f96cfd31f6e9b6018cfdc (patch)
treeaa85169f79c13abe8088bd02737fff4e967cfff1
parent10373d40ffee109d168fa3e90f03d9f381ac8eb0 (diff)
duck_streams.clj: support Socket in reader & writer; fixes #46
Patch by Sean Devlin
-rw-r--r--src/clojure/contrib/duck_streams.clj12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/clojure/contrib/duck_streams.clj b/src/clojure/contrib/duck_streams.clj
index f15e0ee4..027aae4d 100644
--- a/src/clojure/contrib/duck_streams.clj
+++ b/src/clojure/contrib/duck_streams.clj
@@ -64,7 +64,7 @@
OutputStreamWriter BufferedWriter Writer
FileInputStream FileOutputStream ByteArrayOutputStream
StringReader ByteArrayInputStream)
- (java.net URI URL MalformedURLException)))
+ (java.net URI URL MalformedURLException Socket)))
(def
@@ -100,7 +100,7 @@
(defmulti #^{:tag BufferedReader
:doc "Attempts to coerce its argument into an open
java.io.BufferedReader. Argument may be an instance of Reader,
- BufferedReader, InputStream, File, URI, URL, or String.
+ BufferedReader, InputStream, File, URI, URL, Socket, or String.
If argument is a String, it tries to resolve it first as a URI, then
as a local file name. URIs with a 'file' protocol are converted to
@@ -134,6 +134,9 @@
(catch MalformedURLException e
(reader (File. x)))))
+(defmethod reader Socket [#^Socket x]
+ (reader (.getInputStream x)))
+
(defmethod reader :default [x]
(throw (Exception. (str "Cannot open " (pr-str x) " as a reader."))))
@@ -149,7 +152,7 @@
:doc "Attempts to coerce its argument into an open java.io.PrintWriter
wrapped around a java.io.BufferedWriter. Argument may be an
instance of Writer, PrintWriter, BufferedWriter, OutputStream, File,
- URI, URL, or String.
+ URI, URL, Socket, or String.
If argument is a String, it tries to resolve it first as a URI, then
as a local file name. URIs with a 'file' protocol are converted to
@@ -202,6 +205,9 @@
(catch MalformedURLException err
(writer (File. x)))))
+(defmethod writer Socket [#^Socket x]
+ (writer (.getOutputStream x)))
+
(defmethod writer :default [x]
(throw (Exception. (str "Cannot open <" (pr-str x) "> as a writer."))))