Last active
October 10, 2015 17:08
-
-
Save vsnguyen/993d067e510dbadf06d4 to your computer and use it in GitHub Desktop.
clojure: write to bytearrayinputstream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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