|
11 | 11 | [nrepl.misc :refer [response-for]] |
12 | 12 | [nrepl.transport :as transport]) |
13 | 13 | (:import |
14 | | - (java.io ByteArrayOutputStream) |
15 | | - (java.net MalformedURLException URL) |
| 14 | + (java.io ByteArrayOutputStream InputStream) |
| 15 | + (java.net MalformedURLException URL URLConnection) |
16 | 16 | (java.nio.file Files Path Paths) |
17 | 17 | (java.util Base64))) |
18 | 18 |
|
|
61 | 61 | [^bytes buff] |
62 | 62 | (.encodeToString (Base64/getEncoder) buff)) |
63 | 63 |
|
64 | | -(defn slurp-reply [location content-type buff] |
| 64 | +(defn slurp-reply [location content-type ^bytes buff] |
65 | 65 | (let [^String real-type (first content-type) |
66 | 66 | binary? (= "application/octet-stream" real-type) |
67 | 67 | text? (.contains real-type "text")] |
|
82 | 82 | (defn slurp-url-to-content+body |
83 | 83 | "Attempts to parse and then to slurp a URL, producing a content-typed response." |
84 | 84 | [url-str] |
85 | | - (if-let [url (try (URL. url-str) |
86 | | - (catch MalformedURLException e nil))] |
| 85 | + (if-let [^URL url (try (URL. url-str) |
| 86 | + (catch MalformedURLException e nil))] |
87 | 87 | (if (= (.getProtocol url) "file") ;; expected common case |
88 | 88 | (let [^Path p (Paths/get (.toURI url)) |
89 | 89 | content-type (normalize-content-type (get-file-content-type p)) |
90 | 90 | buff (Files/readAllBytes p)] |
91 | 91 | (slurp-reply p content-type buff)) |
92 | 92 |
|
93 | 93 | ;; It's not a file, so just try to open it on up |
94 | | - (let [conn (.openConnection url) |
| 94 | + (let [^URLConnection conn (.openConnection url) |
95 | 95 | content-type (normalize-content-type |
96 | 96 | (.getContentType conn)) |
97 | 97 | ;; FIXME (arrdem 2018-04-03): |
98 | 98 | ;; There's gotta be a better way here |
99 | | - is (.getInputStream conn) |
| 99 | + ^InputStream is (.getInputStream conn) |
100 | 100 | os (ByteArrayOutputStream.)] |
101 | 101 | (loop [] |
102 | 102 | (let [b (.read is)] |
|
0 commit comments