Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Base64 to modern Java #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
(defproject org.flatland/useful "0.11.7-SNAPSHOT"
:description "A collection of generally-useful Clojure utility functions"
:license {:name "Eclipse Public License - v 1.0"
:url "http://www.eclipse.org/legal/epl-v10.html"
:license {:name "Eclipse Public License - v 1.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to only make the changes to the dependencies here without the reformatting?

:url "http://www.eclipse.org/legal/epl-v10.html"
:distribution :repo}
:url "https://github.com/amalloy/useful"
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/tools.macro "0.1.1"]
[org.clojure/tools.reader "0.7.2"]]
:aliases {"testall" ["with-profile" "1.6:1.7:1.8:1.9:1.10" "test"]}
:profiles {:1.10 {:dependencies [[org.clojure/clojure "1.10.0-RC3"]]}
:1.9 {}
:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
:1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}
:1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]}}
:dependencies [[org.clojure/clojure "1.8.0" :scope "provided"]
[org.clojure/tools.macro "0.1.5"]
[org.clojure/tools.reader "1.3.2"]]
:aliases {"testall" ["with-profile" ":1.8:1.9:1.10" "test"]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:aliases {"testall" ["with-profile" ":1.8:1.9:1.10" "test"]}
:aliases {"testall" ["with-profile" "1.8:1.9:1.10" "test"]}

The : here is a delimiter, not part of the profile name itself so we don't need a leading one.


:profiles {:dev {:dependencies [[org.clojure/clojure "1.10.1"]]}
:1.10 {:dependencies [[org.clojure/clojure "1.10.1"]]}
:1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]}
:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}}
:deploy-repositories [["releases" :clojars]
["snapshots" :clojars]]
:plugins [[codox "0.8.0"]]
:codox {:src-dir-uri "http://github.com/flatland/useful/blob/develop/"
:plugins [[codox "0.8.0"]
[lein-ancient "0.6.15"]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we need this in the plugins here?


:codox {:src-dir-uri "http://github.com/flatland/useful/blob/develop/"
:src-linenum-anchor-prefix "L"})
18 changes: 10 additions & 8 deletions src/flatland/useful/compress.clj
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
(ns flatland.useful.compress
(:import [java.util.zip DeflaterOutputStream InflaterInputStream]
[java.io ByteArrayOutputStream ByteArrayInputStream]
[sun.misc BASE64Decoder BASE64Encoder]))
(:import
[java.io ByteArrayOutputStream ByteArrayInputStream]
[java.util Base64]
[java.util.zip DeflaterOutputStream InflaterInputStream] ))

(defn smash [^String str]
(defn smash [str]
(let [out (ByteArrayOutputStream.)]
(doto (DeflaterOutputStream. out)
(.write (.getBytes str))
(.finish))
(-> (BASE64Encoder.)
(.encodeBuffer (.toByteArray out)))))
(-> (Base64/getEncoder)
(.encode (.toByteArray out)))))

(defn unsmash [^String str]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the type hint back in? There will be reflection without it.

(let [bytes (-> (BASE64Decoder.) (.decodeBuffer str))
(defn unsmash [str]
(let [bytes (-> (Base64/getDecoder) (.decode str))
in (ByteArrayInputStream. bytes)]
(slurp (InflaterInputStream. in))))

17 changes: 17 additions & 0 deletions test/flatland/_bootstrap.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(ns flatland._bootstrap
(:require
[clojure.test :refer :all]
[clojure.string :as str] ))

(defn print-versions []
(let [version-str (format " Clojure %s Java %s"
(clojure-version) (System/getProperty "java.version"))
num-hyphen (+ 6 (count version-str))
hyphens (str/join (repeat num-hyphen \-)) ]
(newline)
(println hyphens)
(println version-str)
(println hyphens)))

(deftest t-bootstrap-16
(print-versions))