我想在我的 Clojure 基准测试中重定向标准输入。我已将文件作为参数传递,我试图在 java 中找到等效代码: System.setIn(new FileInputStream(filename)); 但是对于Clojure。
主要问题是我使用 DaCapo 套件来计算 Benchmark 的性能,并且与 cmd 相比,加载基准测试的方法无法识别像“<”这样的特殊字符(直接从 cmd 运行基准测试的 jar ..)。
这就是我想要做的..但仍然不起作用..我认为 br 具有来自 in 的标准输入,并且它被程序的其余部分使用。当我在 args 中有所需的路径时,如何更改 in,以便我可以正确运行基准测试?这是我对“系统/设置”的努力
(defn -main [& args]
(let [max-dna-chars-per-line 60
jk (with-open [is (clojure.java.io/input-stream (first args))]
(System/setIn is))
br (java.io.BufferedReader. *in*)
bw (java.io.BufferedWriter. *out* (* 16 8192)) ; 16 * default size, I think
;; We could use the map complement-dna-char-map instead of
;; complement-dna-char-fn, but when I tested that, the program
;; spent a lot of time running the hashCode method on
;; characters. I'm hoping this is faster.
complement-dna-char-vec (make-vec-char-mapper complement-dna-char-map)]
(loop [[desc-str dna-seq-str more] (fasta-slurp-br br)]
(println-string-to-buffered-writer bw desc-str)
(print-reverse-complement-of-str-in-lines bw dna-seq-str
complement-dna-char-vec
max-dna-chars-per-line)
(when more
(recur (fasta-slurp-br br))))
(. bw flush)))