(defn buffer-stream
"Returns an InputStream for a ByteBuffer, such as returned by mmap."
[^ByteBuffer buf]
(proxy [InputStream] []
(available [] (.remaining buf))
(read
([] (if (.hasRemaining buf) (.get buf) -1))
([dst offset len] (let [actlen (min (.remaining buf) len)]
(.get buf dst offset actlen)
(if (< actlen 1) -1 actlen))))))
Comments top
No comments for buffer-stream. Log in to add a comment.