Proxy support for PipedInputStream and PipedOutputStream

* Spire requires proxy support for java.io.PipedInputStream and java.io.PipedOutputStream

* proxy support for java.io.PipedInputStream and java.io.PipedOutputStream

* proxy tests for PipedInputStream and PipedOutputStream

Co-authored-by: Crispin Wellington <retrogradeorbit@gmail.com>
This commit is contained in:
Michiel Borkent 2022-03-31 10:00:16 +02:00 committed by GitHub
parent bee5a88d16
commit 4d24cdca2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 1 deletions

View file

@ -17,6 +17,10 @@ A preview of the next release can be installed from
- [#1216](https://github.com/babashka/babashka/issues/1216): support `core.async/alts!` using polyfill
- [#1220](https://github.com/babashka/babashka/issues/1220): add reflection on java.util.concurrent.Future
## 0.7.9-SNAPSHOT
- [#1224](https://github.com/babashka/babashka/issues/1224): add `proxy` support for `java.io.PipedInputStream` and `java.io.PipedOutputStream`. Add reflection for `java.utils.Scanner`.
## 0.7.8 (2022-03-13)
This release improves compatibility with several libraries: [loom](https://github.com/aysylu/loom), [hugsql.core](https://www.hugsql.org) and [specter](https://github.com/redplanetlabs/specter)!

View file

@ -383,6 +383,7 @@
java.util.NoSuchElementException
java.util.Optional
java.util.Properties
;; java.util.Scanner
java.util.Set
java.util.StringTokenizer
java.util.UUID

View file

@ -72,7 +72,27 @@
["javax.net.ssl.HostnameVerifier" #{}]
(proxy [javax.net.ssl.HostnameVerifier] []
(verify [host-name session] ((method-or-bust methods 'verify) this host-name session))))))
(verify [host-name session] ((method-or-bust methods 'verify) this host-name session)))
["java.io.PipedInputStream" #{}]
(proxy [java.io.PipedInputStream] []
(available [] ((method-or-bust methods 'available) this))
(close [] ((method-or-bust methods 'close) this))
(read
([]
((method-or-bust methods 'read) this))
([b off len]
((method-or-bust methods 'read) this b off len)))
(receive [b] ((method-or-bust methods 'receive) this b)))
["java.io.PipedOutputStream" #{}]
(proxy [java.io.PipedOutputStream] []
(close [] ((method-or-bust methods 'close) this))
(connect [snk] ((method-or-bust methods 'connect) this snk))
(flush [] ((method-or-bust methods 'flush) this))
(write
([b] ((method-or-bust methods 'write) this b))
([b off len] ((method-or-bust methods 'write) this b off len)))))))
(defn class-sym [c] (symbol (class-name c)))

View file

@ -78,3 +78,51 @@
true
false]
(bb (with-out-str (clojure.pprint/pprint code))))))
(deftest PipedInputStream-PipedOutputStream-proxy-test
(is (= {:available 1
:read-result -1
:byte-read 10
:array-read '(0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0)
:instance? true}
(bb (with-out-str
(clojure.pprint/pprint
'(let [ins (proxy [java.io.PipedInputStream] []
(available [] 1)
(close [] nil)
(read
([] 10)
([byte-arr off len]
(aset byte-arr off (byte 10))
-1))
(receive [b]
nil))
arr (byte-array 16)
]
{:available (.available ins)
:read-result (.read ins arr 6 2)
:byte-read (.read ins)
:array-read (seq arr)
:instance? (instance? java.io.PipedInputStream ins)}))))))
(is (= {:instance? true
:arr '(1 2 3 4 5 0 0 0)
:arr2 '(10)}
(bb (with-out-str
(clojure.pprint/pprint
'(let [arr (byte-array 8)
arr2 (byte-array 1)
outs (proxy [java.io.PipedOutputStream] []
(close [] nil)
(connect [sink] nil)
(flush [] nil)
(write
([b] (aset arr2 0 (byte b)))
([byte-arr off len]
(doseq [n (range len)]
(aset arr n (aget byte-arr (+ off n)))))))]
(.write outs (int 10))
(.write outs (byte-array [0 0 0 1 2 3 4 5 0 0 0]) 3 5)
{:instance? (instance? java.io.PipedOutputStream outs)
:arr (seq arr)
:arr2 (seq arr2)})))))))