This is the mail archive of the java-discuss@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PrintWriter again


Oskar> According to the Sun JDK 1.3 api docs, println(whatever) in
Oskar> PrintWriter should call print(whatever) and then println().  At
Oskar> least that's how I interpret the documentation:

Oskar> "This method behaves as though it invokes print(boolean) and
Oskar> then println()."

That "as if" is important.

Oskar> The reason for this is that it makes it easy for a subclass of
Oskar> PrintWriter to catch all newline-writes by overriding a single
Oskar> method.  In my IndentWriter I buffer all non-newline terminated
Oskar> text, and when println is called I format and finally print the
Oskar> buffered text.

What do you do if print(String) is called and the string has an
embedded newline?

Oskar> The libgcj implementation of println(whatever) calls first
Oskar> print(whatever) then the private method printlnUnsynchronized.
Oskar> I would rather see it behave like the Sun implementation.

I agree that this would be more useful, but my reading of the docs is
that this is not a portable assumption.

However, I don't have a very strong feeling about this.  Obviously
this change is going to have a performance cost, but it can't be very
large.  So I'm inclined to make this change.  Anybody oppose this?

Tom

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]