Daniel Compton
Daniel Compton

Reputation: 14549

Using Apache Commons Codec decodeBase64 from Clojure

I am trying to decode a base64 string in Clojure using the Apache Commons Codec library.

I am able to use these methods in the library:

(ns decode.core
  (:import (org.apache.commons.codec.binary Base64 Hex))
  (:gen-class))

(.encode (Hex.) "s")
(.decode (Hex.) "0a")
(.decode (Base64.) "s")

But when I try to use decodeBase64 like (.decodeBase64 (Base64.) "s") I get

IllegalArgumentException No matching method found: decodeBase64 for class
org.apache.commons.codec.binary.Base64  clojure.lang.Reflector.invokeMatchingMethod
(Reflector.java:53)

What am I doing wrong? It seems like I should be able to call decodeBase64 just like I can call decode?

Upvotes: 0

Views: 617

Answers (1)

Nicolas Modrzyk
Nicolas Modrzyk

Reputation: 14187

decodeBase64 is a static java method. Here is how you call it in Clojure:

 (import '[org.apache.commons.codec.binary Base64 Hex])
 (Base64/decodeBase64 "s")

Upvotes: 4

Related Questions