Permalink
Browse files

Merge pull request #28 from markokocic/no-reflection

Remove reflection warnings in ring-core
  • Loading branch information...
2 parents c3b7a67 + 5ff053c commit 860fbdd825b4fbe83ec67dad4009ce7bc0b0117a @weavejester weavejester committed Nov 10, 2012
@@ -11,4 +11,4 @@
[]
(fn [item]
(-> (select-keys item [:filename :content-type])
- (assoc :bytes (IOUtils/toByteArray (:stream item))))))
+ (assoc :bytes (IOUtils/toByteArray ^java.io.InputStream (:stream item))))))
@@ -2,7 +2,7 @@
(:require [clojure.java.io :as io])
(:import java.io.File))
-(defn- background-thread [f]
+(defn- background-thread [^Runnable f]
(doto (Thread. f)
(.setDaemon true)
(.start)))
@@ -8,7 +8,7 @@
(if-let [etag (get-in response [:headers "etag"])]
(= etag (get-in request [:headers "if-none-match"]))))
-(defn- date-header [response header]
+(defn- ^java.util.Date date-header [response header]
(if-let [http-date (get-in response [:headers header])]
(parse-date http-date)))
@@ -13,25 +13,25 @@
(defn percent-encode
"Percent-encode every character in the given string using either the specified
encoding, or UTF-8 by default."
- [unencoded & [encoding]]
+ [^String unencoded & [^String encoding]]
(->> (.getBytes unencoded (or encoding "UTF-8"))
(map (partial format "%%%02X"))
(str/join)))
(defn- parse-bytes [encoded-bytes]
(->> (re-seq #"%.." encoded-bytes)
(map #(subs % 1))
- (map #(.byteValue (Integer/parseInt % 16)))
+ (map #(.byteValue (Integer/valueOf % 16)))
(byte-array)))
(defn percent-decode
"Decode every percent-encoded character in the given string using the
specified encoding, or UTF-8 by default."
- [encoded & [encoding]]
+ [^String encoded & [^String encoding]]
(str/replace encoded
#"(?:%..)+"
(fn [chars]
- (-> (parse-bytes chars)
+ (-> ^bytes (parse-bytes chars)
(String. (or encoding "UTF-8"))
(double-escape)))))
@@ -44,7 +44,7 @@
#"[^A-Za-z0-9_~.+-]+"
#(double-escape (percent-encode % encoding))))
-(defn url-decode
+(defn ^String url-decode
"Returns the url-decoded version of the given string, using either a specified
encoding or UTF-8 by default. If the encoding is invalid, nil is returned."
[encoded & [encoding]]
@@ -101,7 +101,7 @@
"Decode the supplied www-form-urlencoded string using the specified encoding,
or UTF-8 by default. If the encoded value is a string, a string is returned.
If the encoded value is a map of parameters, a map is returned."
- [encoded & [encoding]]
+ [^String encoded & [encoding]]
(if-not (.contains encoded "=")
(form-decode-str encoded encoding)
(reduce
@@ -29,13 +29,13 @@
"Returns a ByteArrayInputStream for the given String."
([^String s]
(ByteArrayInputStream. (.getBytes s)))
- ([^String s encoding]
+ ([^String s ^String encoding]
(ByteArrayInputStream. (.getBytes s encoding))))
(defn close!
"Ensure a stream is closed, swallowing any exceptions."
[stream]
(when (instance? java.io.Closeable stream)
(try
- (.close stream)
+ (.close ^java.io.Closeable stream)
(catch IOException _ nil))))
@@ -96,12 +96,12 @@
;; As a work-around, we'll backport the fix from the Clojure master
;; branch into url-as-file.
-(defn- url-as-file [u]
+(defn- ^File url-as-file [^java.net.URL u]
(io/as-file
(str/replace
(.replace (.getFile u) \/ File/separatorChar)
#"%.."
- (fn [escape]
+ (fn [^String escape]
(-> escape
(.substring 1 3)
(Integer/parseInt 16)
@@ -11,8 +11,8 @@
:rfc1036 "EEEE, dd-MMM-yy HH:mm:ss zzz"
:asctime "EEE MMM d HH:mm:ss yyyy"})
-(defn- formatter [format]
- (doto (SimpleDateFormat. (http-date-formats format) Locale/US)
+(defn- ^SimpleDateFormat formatter [format]
+ (doto (SimpleDateFormat. ^String (http-date-formats format) Locale/US)
(.setTimeZone (TimeZone/getTimeZone "GMT"))))
(defn- attempt-parse [date format]
@@ -26,10 +26,10 @@
(let [context (SslContextFactory.)]
(if (string? (options :keystore))
(.setKeyStorePath context (options :keystore))
- (.setKeyStore context (options :keystore)))
+ (.setKeyStore context ^java.security.KeyStore (options :keystore)))
(.setKeyStorePassword context (options :key-password))
(when (options :truststore)
- (.setTrustStore context (options :truststore)))
+ (.setTrustStore context ^java.security.KeyStore (options :truststore)))
(when (options :trust-password)
(.setTrustStorePassword context (options :trust-password)))
(case (options :client-auth)
@@ -78,7 +78,7 @@
:want or :none (defaults to :none)"
[handler options]
(let [^Server s (create-server (dissoc options :configurator))
- ^QueuedThreadPool p (QueuedThreadPool. (options :max-threads 50))]
+ ^QueuedThreadPool p (QueuedThreadPool. ^Integer (options :max-threads 50))]
(when (:daemon? options false)
(.setDaemon p true))
(doto s

0 comments on commit 860fbdd

Please sign in to comment.