buffer-stream

clojure.contrib.mmap

  • (buffer-stream buf)
Returns an InputStream for a ByteBuffer, such as returned by mmap.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/mmap.clj:39 top

(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))))))
Vars in clojure.contrib.mmap/buffer-stream: < defn let proxy read
Used in 0 other vars

Comments top

No comments for buffer-stream. Log in to add a comment.