Skip to content

Commit

Permalink
Merge pull request #1 from athos/fix/verify-error
Browse files Browse the repository at this point in the history
Fix VerifyError on some environments
  • Loading branch information
athos committed Aug 16, 2020
2 parents c1ba9e4 + fa337e1 commit e8905f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/pogonos/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#?(:clj [pogonos.partials :as partials])
[pogonos.reader :as reader]
[pogonos.render :as render])
#?(:clj (:import [java.io Closeable FileNotFoundException])))
#?(:clj (:import [java.io FileNotFoundException])))

(def ^:private default-options (atom nil))

Expand Down Expand Up @@ -66,7 +66,7 @@
(let [f (io/as-file file)]
(if (.exists f)
(let [opts (fixup-options opts partials/file-partials)]
(with-open [in ^Closeable (reader/make-file-reader f)]
(with-open [in (reader/make-file-reader f)]
(parse-input in opts)))
(throw (FileNotFoundException. (.getName f))))))))

Expand All @@ -81,7 +81,7 @@
([res opts]
(if-let [res (io/resource res)]
(let [opts (fixup-options opts partials/resource-partials)]
(with-open [in ^Closeable (reader/make-file-reader res)]
(with-open [in (reader/make-file-reader res)]
(parse-input in opts)))
(throw (FileNotFoundException. res))))))

Expand Down Expand Up @@ -141,7 +141,7 @@
(let [opts (-> opts
(fixup-options partials/file-partials)
(assoc :source (.getName f)))]
(with-open [in ^Closeable (reader/make-file-reader f)]
(with-open [in (reader/make-file-reader f)]
(render-input in data opts)))
(throw (FileNotFoundException. (.getName f))))))))

Expand All @@ -157,7 +157,7 @@
(if-let [res (io/resource res)]
(let [opts (cond-> (fixup-options opts partials/resource-partials)
(string? res) (assoc :source res))]
(with-open [in ^Closeable (reader/make-file-reader res)]
(with-open [in (reader/make-file-reader res)]
(render-input in data opts)))
(throw (FileNotFoundException. res))))))

Expand Down
7 changes: 3 additions & 4 deletions src/pogonos/reader.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#?(:clj [clojure.java.io :as io])
[pogonos.protocols :as proto]
[pogonos.strings :as pstr])
#?(:clj (:import [java.io Reader Closeable])))
#?(:clj (:import [java.io Reader])))

(defn ->reader [x]
(if (satisfies? proto/IReader x)
Expand All @@ -24,7 +24,7 @@
ret)))
(close [this]))

(defn make-string-reader [s]
(defn ^StringReader make-string-reader [s]
(StringReader. s 0))

(extend-protocol proto/ToReader
Expand Down Expand Up @@ -61,12 +61,11 @@
(do (.append sb buf offset (- size offset))
(set! offset size)
(recur sb)))))))
Closeable
(close [this]
(.close reader))))

#?(:clj
(defn make-file-reader [file]
(defn ^FileReader make-file-reader [file]
(FileReader. (io/reader file) (char-array 256) 0 0)))

#?(:clj
Expand Down
8 changes: 5 additions & 3 deletions test/pogonos/reader_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
(:require [clojure.test :refer [deftest is testing]]
[pogonos.protocols :as proto]
[pogonos.reader :as reader])
#?(:clj (:import [java.io Closeable File])))
#?(:clj
(:import [java.io File]
[pogonos.reader FileReader])))

(deftest string-reader-test
(let [r (reader/make-string-reader "")]
Expand All @@ -28,7 +30,7 @@
(is (nil? (proto/read-line r)))))

#?(:clj
(defn- ^Closeable make-file-reader [content]
(defn- ^FileReader make-file-reader [content]
(-> (doto (File/createTempFile "tmp" nil)
(spit content))
(reader/make-file-reader))))
Expand Down Expand Up @@ -57,7 +59,7 @@
(is (= "baz\n" (proto/read-line r)))
(is (nil? (proto/read-line r))))))

(defn- ^Closeable make-line-buffering-reader [content]
(defn- make-line-buffering-reader [content]
(reader/make-line-buffering-reader (reader/make-string-reader content)))

(deftest line-buffering-reader-test
Expand Down

0 comments on commit e8905f7

Please sign in to comment.