Best Choice of Java Class For *out*

7 views
Skip to first unread message

Randall R Schulz

unread,
Dec 14, 2008, 8:21:59 PM12/14/08
to clo...@googlegroups.com
Hi,

I have quite a bit of Java code with I/O capabilities that generally
support both PrintStream and PrintWriter. I was a bit perplexed when I
tried to apply one of these methods to *out* and was rebuffed thusly:

java.lang.IllegalArgumentException:
No matching method found: printMessage for class rrs.util.ErrorRecord

As Rich then pointed out to me on #clojure, the problem is that the
concrete type of *out* is:

user=> (class *out*)
java.io.OutputStreamWriter


This leaves almost all of my system's I/O primitives high and dry.

What might be the issues or consequences of making the root binding of
*out* a PrintWriter?


Randall Schulz

Albert Cardona

unread,
Dec 15, 2008, 4:16:43 AM12/15/08
to clo...@googlegroups.com
Randall R Schulz wrote:
> What might be the issues or consequences of making the root binding of
> *out* a PrintWriter?
>


I've been using a PrintWriter for *out* for months now, and no problems
so far.
Using always nearly latest svn clojure.

Albert

--
Albert Cardona
http://albert.rierol.net

Randall R Schulz

unread,
Dec 15, 2008, 9:11:25 AM12/15/08
to clo...@googlegroups.com
On Monday 15 December 2008 01:16, Albert Cardona wrote:
> Randall R Schulz wrote:
> > What might be the issues or consequences of making the root binding
> > of *out* a PrintWriter?
>
> I've been using a PrintWriter for *out* for months now, and no
> problems so far. Using always nearly latest svn clojure.

You're _changing_ *out* to a PrintWriter. I'm talking about making the
root binding of *out* a PrintWriter wrapped around System.out.


> Albert


Randall Schulz

Randall R Schulz

unread,
Dec 15, 2008, 6:08:18 PM12/15/08
to clo...@googlegroups.com
On Sunday 14 December 2008 17:21, Randall R Schulz wrote:
> Hi,
>
> I have quite a bit of Java code with I/O capabilities that generally
> support both PrintStream and PrintWriter. I was a bit perplexed when
> I tried to apply one of these methods to *out* and was rebuffed
> thusly:
>
> java.lang.IllegalArgumentException:
> No matching method found: printMessage for class
> rrs.util.ErrorRecord
>
> As Rich then pointed out to me on #clojure, the problem is that the
> concrete type of *out* is:
>
> user=> (class *out*)
> java.io.OutputStreamWriter

Perhaps a bit odd is this:

user=> (class *err*)
java.io.PrintWriter


Randall Schulz

(pretty clever way to do a bump, eh?)

Stephen C. Gilardi

unread,
Dec 15, 2008, 6:22:01 PM12/15/08
to clo...@googlegroups.com

On Dec 15, 2008, at 6:08 PM, Randall R Schulz wrote:

user=> (class *err*)
java.io.PrintWriter

PrintWriter is (as far as I can determine) the more modern of the two classes that are accepted as an argument to "Throwable.printStackTrace" which is used frequently in Clojure's implementation. *err* also has the "autoflush" option turned on which is not appropriate for *out*.

I've thought of suggesting PrintWriter for *out* in the past, but I saw that for Clojure's implementation, only OutputStreamWriter is required. If you have a need for a PrintWriter you can bind *out* to one, or better yet, use another dynamic variable to hold a PrintWriter with *out* as its sink.

Would that be sufficient to accomplish your goal?

--Steve

Randall R Schulz

unread,
Dec 15, 2008, 7:13:26 PM12/15/08
to clo...@googlegroups.com

Well, if *out* continues to be a vanilla (non-Print-) Writer, then it
will have to be, I suppose.

I consider it pretty fragile to work with an altered root binding for
*out*, so I doubt I'll go that route. On the other hand, having
multiple paths that ultimately converge on System/out leads to the
potential for out-of-order appearance of data directed through those
disparate paths when they are liberal in their flushing policy (which
in this context means they do rather little of it).

So from my perspective there's no ideal solution under the current
circumstances. I really don't know why *out* (its initial root binding)
should _not_ be a PrintWriter, especially when it is ultimately
directed at System/out, which is itself a PrintStream.

And why is *err* a PrintWriter when *out* is not?

Consider, too, that PrintWriter has format(...) / printf(...) methods
not available on any non-Print Writer class.


> --Steve


Randall Schulz

Reply all
Reply to author
Forward
0 new messages