Back

make-input-stream (clj)

(source)

protocol

(make-input-stream x opts)
Creates a BufferedInputStream. See also IOFactory docs.

Examples

metosin/muuntaja
(ns muuntaja.protocols
  (:require [clojure.java.io :as io]
            [muuntaja.util :as util])
  (:import (clojure.lang IFn AFn)
           (java.io ByteArrayOutputStream ByteArrayInputStream InputStreamReader BufferedReader InputStream Writer OutputStream FileInputStream File)))

(extend StreamableResponse
  io/IOFactory
  (assoc io/default-streams-impl
    :make-input-stream (fn [^StreamableResponse this _]
                         (with-open [out (ByteArrayOutputStream. 4096)]
                           ((.f this) out)
                           (ByteArrayInputStream.
                             (.toByteArray out))))
    :make-reader (fn [^StreamableResponse this _]
                   (with-open [out (ByteArrayOutputStream. 4096)]
                     ((.f this) out)
                     (BufferedReader.
                       (InputStreamReader.
                         (ByteArrayInputStream.
                           (.toByteArray out))))))))

  StreamableResponse
  (into-input-stream [this]
    (io/make-input-stream this nil))
aliostad/deep-learning-lang-detection
(ns muuntaja.protocols
  (:require [clojure.java.io :as io]
            ring.core.protocols)
  (:import (clojure.lang IFn AFn)
           (java.io ByteArrayOutputStream ByteArrayInputStream InputStreamReader BufferedReader InputStream Writer)))

(extend StreamableResponse
  io/IOFactory
  (assoc io/default-streams-impl
    :make-input-stream (fn [^StreamableResponse this _]
                         (with-open [out (ByteArrayOutputStream. 4096)]
                           ((.f this) out)
                           (ByteArrayInputStream.
                             (.toByteArray out))))
    :make-reader (fn [^StreamableResponse this _]
                   (with-open [out (ByteArrayOutputStream. 4096)]
                     ((.f this) out)
                     (BufferedReader.
                       (InputStreamReader.
                         (ByteArrayInputStream.
                           (.toByteArray out))))))))

  StreamableResponse
  (as-input-stream [this]
    (io/make-input-stream this nil))
zcaudate/foundation-base
(ns std.fs.interop
  (:require [clojure.java.io]
            [std.fs.path :as path])
  (:import (java.nio.file Path)))

(extend Path
  clojure.java.io/IOFactory
  (assoc clojure.java.io/default-streams-impl
         :make-input-stream  (fn [path opts] (path/input-stream path))
         :make-output-stream (fn [path opts] (path/output-stream path))))