Back
output-stream (clj)
(source)function
(output-stream x & opts)
Attempts to coerce its argument into an open java.io.OutputStream.
Default implementations always return a java.io.BufferedOutputStream.
Default implementations are defined for OutputStream, File, URI, URL,
Socket, and String arguments.
If the argument is a String, it tries to resolve it first as a URI, then
as a local file name. URIs with a 'file' protocol are converted to
local file names.
Should be used inside with-open to ensure the OutputStream is
properly closed.
Examples
thi-ng/geom
(ns thi.ng.geom.examples.voxel.noise
(:require
[thi.ng.geom.core :as g]
[thi.ng.geom.vector :refer [vec3]]
[thi.ng.geom.voxel.svo :as svo]
[thi.ng.geom.voxel.isosurface :as iso]
[thi.ng.geom.mesh.io :as mio]
[thi.ng.math.core :as m]
[clojure.java.io :as io]
[thi.ng.math.noise :as n]))
(time
(with-open [o (io/output-stream "out/voxel-noise.stl")]
(mio/write-stl
(mio/wrapped-output-stream o)
(g/tessellate (iso/surface-mesh v 10 iso-val)))))
Netflix/PigPen
(ns pigpen.functional.io-test
(:require [pigpen.functional-test :as t]
[pigpen.extensions.test :refer [test-diff]]
[pigpen.io :as pig-io]
[clojure.java.io :as io])
(:import [java.util.zip GZIPOutputStream]))
(t/deftest test-load-gz
"gz input"
[harness]
(let [file (str (t/file harness) ".gz")]
(with-open [o (GZIPOutputStream. (io/output-stream file))]
(.write o (.getBytes "{:a 1, :b \"foo\"}\n{:a 2, :b \"bar\"}")))
(test-diff
(->>
(pig-io/load-clj file)
(t/dump harness)
(set))
'#{{:a 2, :b "bar"}
{:a 1, :b "foo"}})))
cloojure/tupelo
; Copyright (c) Alan Thompson. All rights reserved.
; The use and distribution terms for this software are covered by the Eclipse Public
; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can be found in the
; file epl-v10.html at the root of this distribution. By using this software in any
; fashion, you are agreeing to be bound by the terms of this license.
; You must not remove this notice, or any other, from this software.
(ns tst.tupelo.io
(:use tupelo.io tupelo.core tupelo.test)
(:refer-clojure :exclude [read-string])
(:require
[clojure.java.io :as io]
[tupelo.types :as types]
[schema.core :as s]
[clojure.pprint :as pprint])
(:import [java.io DataInputStream DataOutputStream FileOutputStream]))
(let [in-stream (io/input-stream dummy-file)
out-stream (io/output-stream dummy-file)
dis (DataInputStream. in-stream)
dos (DataOutputStream. out-stream)]
(isnt (data-input-stream? in-stream))
(is (input-stream? in-stream))
(is (input-stream? dis))
(is (data-input-stream? dis))
(isnt (data-output-stream? out-stream))
(is (output-stream? out-stream))
(is (output-stream? dos))
(is (data-output-stream? dos))))
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)))
(deftype StreamableResponse [f]
IFn
(invoke [_ output-stream]
(f output-stream)
output-stream)
(applyTo [this args]
(AFn/applyToHelper this args)))
(util/when-ns
'ring.core.protocols
(extend-protocol ring.core.protocols/StreamableResponseBody
(Class/forName "[B")
(write-body-to-stream [body _ ^OutputStream output-stream]
(with-open [out output-stream]
(.write out ^bytes body)))
StreamableResponse
(write-body-to-stream [this _ ^OutputStream output-stream]
(with-open [out output-stream]
((.f this) ^OutputStream out)))))
malcolmsparks/clj-logging-config
(require '[clojure.java.io :as io])
(import (org.apache.log4j PatternLayout FileAppender))
(use 'clojure.tools.logging 'clj-logging-config.log4j)
(with-open [f (io/output-stream (io/file "job-123.log"))]
(with-logging-config [:root {:level :debug :out f :pattern ">>> %d - %m %n"}]
(logf :info "foo")))