Skip to content

Instantly share code, notes, and snippets.

@vsnguyen
Last active October 10, 2015 17:08
Show Gist options
  • Save vsnguyen/993d067e510dbadf06d4 to your computer and use it in GitHub Desktop.
Save vsnguyen/993d067e510dbadf06d4 to your computer and use it in GitHub Desktop.
clojure: write to bytearrayinputstream
;; write
(def write-bs
(let [baos (java.io.ByteArrayOutputStream.)]
(with-open [oos (java.io.ObjectOutputStream. baos)]
(.writeObject oos "hello"))
(.toByteArray baos)))
;; read bs
(defn read-bs
[bs]
(with-open [o (java.io.ObjectInputStream. (java.io.ByteArrayInputStream. bs))]
(.readObject o)))
;;=> (read-bs write-bs)
;;"hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment