Skip to content

Instantly share code, notes, and snippets.

@trptcolin
Created November 28, 2011 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trptcolin/1398988 to your computer and use it in GitHub Desktop.
Save trptcolin/1398988 to your computer and use it in GitHub Desktop.
--- a/src/clj/clojure/java/io.clj
+++ b/src/clj/clojure/java/io.clj
@@ -18,7 +18,7 @@
StringReader ByteArrayInputStream
BufferedInputStream BufferedOutputStream
CharArrayReader Closeable)
- (java.net URI URL MalformedURLException Socket)))
+ (java.net URI URL URLDecoder MalformedURLException Socket)))
(def
^{:doc "Type object for a Java primitive byte array."
@@ -47,13 +47,13 @@
File
(as-file [f] f)
- (as-url [f] (.toURL f))
+ (as-url [f] (.toURL (.toURI f)))
URL
(as-url [u] u)
(as-file [u]
(if (= "file" (.getProtocol u))
- (as-file (.getPath u))
+ (as-file (URLDecoder/decode (.getPath u)))
(throw (IllegalArgumentException. (str "Not a file: " u)))))
URI
@@ -229,11 +229,11 @@
:make-input-stream (fn [^URL x opts]
(make-input-stream
(if (= "file" (.getProtocol x))
- (FileInputStream. (.getPath x))
+ (FileInputStream. (as-file x))
(.openStream x)) opts))
:make-output-stream (fn [^URL x opts]
(if (= "file" (.getProtocol x))
- (make-output-stream (File. (.getPath x)) opts)
+ (make-output-stream (as-file x) opts)
(throw (IllegalArgumentException. (str "Can not write to non-file URL <" x ">")))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment