On Wed, 2008-10-29 at 23:44 -0700, mb wrote:
> But proxy-super to the rescue: You may try the following snippet
> for the write method:

Nice. Never heard of proxy-super before. Would be nice to mention it on
the Java interop page and not only on the API page.

> 
>        (write
>          ([x]
>           (when (>= (.size buffer) 32)
>             (.flush this))
>           (.write buffer x))
>          ([x off len]
>           (proxy-super write x off len)))
> 
> Since there is a write method, we have to call the super-class'
> method explicitely.

Tried it but it fails with:

java.lang.reflect.InvocationTargetException (NO_SOURCE_FILE:0)
        at clojure.lang.Compiler.eval(Compiler.java:4122)
        at clojure.lang.Repl.main(Repl.java:91)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:86)
        at
clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)
        at test.fn__2490$fn__2492$fn__2495.invoke(test.clj:18)
        at clojure.proxy_call_with_super__2077.invoke(proxy.clj:264)
        at test.fn__2490$fn__2492.invoke(test.clj:18)
        at clojure.lang.Proxy__2503.write(Unknown Source)
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202)
        at
sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:272)
        at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:276)
        at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:122)
        at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:212)
        at clojure.flush__906.invoke(boot.clj:1658)
        at clojure.prn__909.doInvoke(boot.clj:1667)
        at clojure.lang.RestFn.invoke(RestFn.java:413)
        at user.eval__2507.invoke(Unknown Source)
        at clojure.lang.Compiler.eval(Compiler.java:4111)
        ... 1 more
Caused by: java.lang.AbstractMethodError: java.io.OutputStream.write(I)V
        at clojure.lang.Proxy__2503.write(Unknown Source)
        at java.io.OutputStream.write(OutputStream.java:99)
        at clojure.lang.Proxy__2503.write(Unknown Source)
        ... 21 more


Interestingly java.io.OutputStream.write(I)V is invoked even though this
should be covered by the proxy write method.

> Hope this helps.

Despite the error it did. Thanks!



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to