Skip to content

Commit 3f41fc5

Browse files
committed
fix 17: java 9 & 20 compatibility
1 parent c0a4645 commit 3f41fc5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/clj_http/lite/util.clj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@
2727
[unencoded]
2828
(URLEncoder/encode unencoded "UTF-8"))
2929

30-
(defn base64-encode
30+
(defmacro base64-encode
3131
"Encode an array of bytes into a base64 encoded string."
3232
[unencoded]
33-
(javax.xml.bind.DatatypeConverter/printBase64Binary unencoded))
33+
(if (try (import 'javax.xml.bind.DatatypeConverter)
34+
(catch ClassNotFoundException _))
35+
`(javax.xml.bind.DatatypeConverter/printBase64Binary ~unencoded)
36+
(do
37+
(import 'java.util.Base64)
38+
`(.encodeToString (java.util.Base64/getEncoder) ~unencoded))))
3439

3540
(defn to-byte-array
3641
"Returns a byte array for the InputStream provided."

0 commit comments

Comments
 (0)