Skip to content

Instantly share code, notes, and snippets.

@puredanger
Created September 10, 2015 22:03
Show Gist options
  • Save puredanger/9cc4304a43de9a67171b to your computer and use it in GitHub Desktop.
Save puredanger/9cc4304a43de9a67171b to your computer and use it in GitHub Desktop.
Example of using gen-class to subclass a class with multi-arity method
(ns example.ByteInputStream
(:gen-class
:extends java.io.InputStream
:state byteseq
:init init
:constructors {[clojure.lang.Seqable] []}
:exposes-methods {read readSuper}
:main false))
(defn -init [byte-seq]
[[] (ref byte-seq)])
(defn -read
([this] (dosync
(let [byte-seq (.byteseq this)
[b & more-bytes] @byte-seq]
(ref-set byte-seq more-bytes)
(if b b -1))))
([this byte-arr] (.readSuper this byte-arr))
([this byte-arr off len] (.readSuper this byte-arr off len)))
(comment
(compile 'example.ByteInputStream)
(def bis (example.ByteInputStream. [67 108 111 106 117 114 101]))
(slurp bis)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment