Skip to content

Instantly share code, notes, and snippets.

@akovantsev
Created April 11, 2023 15:57
Show Gist options
  • Save akovantsev/b1ce434ab49b8d021ffc1f844ac32c2c to your computer and use it in GitHub Desktop.
Save akovantsev/b1ce434ab49b8d021ffc1f844ac32c2c to your computer and use it in GitHub Desktop.
string to plantuml url
(ns foo
(:import
java.io.ByteArrayOutputStream
java.util.zip.Deflater
java.util.zip.DeflaterOutputStream))
;; https://plantuml.com/text-encoding
;; https://gist.github.com/ryardley/88001f6822975ece088d41768431f5d6
;; https://github.com/funcool/buddy-core/blob/b152bc77597975770c347f3bc23c8d5833237b25/src/buddy/util/deflate.clj#L28
(defn str->plantuml-url [raw-str]
(let [os (new ByteArrayOutputStream)
deflater (new Deflater Deflater/DEFLATED (boolean "nowrap"))
_ (with-open [dos (new DeflaterOutputStream os deflater)]
(.write dos (.getBytes raw-str)))
deflated (.toByteArray os)
b64-string (new String (.encode (java.util.Base64/getEncoder) deflated))
b64->plant (zipmap
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_")
uml-string (->> b64-string (map b64->plant) (str/join))]
(str "http://www.plantuml.com/plantuml/uml/" uml-string)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment