Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
--- 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
You can’t perform that action at this time.