EVALUATION
This issue needs to be resolved before we ship tiger.
-- iag@sfbay 2004-02-04
Actually, PrintStream.print("Hello") doesn't autoflush. PrintStream.print("Hello\n") will autoflush.
For output stream s = PrintStream:
The flushing behaviour of format/printf can be made consistent with existing
methods on PrintStream by ignoring the autoflush field and allowing the
internal write methods on PrintStream to handle flushing as necessary based on
the content of the data being written.
All we need to do is remove the autoflush tests:
***************
*** 897,904 ****
|| (formatter.locale() != Locale.getDefault()))
formatter = new Formatter((Appendable) this);
formatter.format(Locale.getDefault(), format, args);
- if (autoFlush)
- out.flush();
}
} catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
--- 897,902 ----
***************
*** 956,963 ****
|| (formatter.locale() != l))
formatter = new Formatter(this, l);
formatter.format(l, format, args);
- if (autoFlush)
- out.flush();
}
} catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
The remaining specification in this class requires no changes.
For output stream s = PrintWriter:
PrintWriter controls flushing based upon the methods that are called (rather
than whether a new line happens to appear in the output). Therefore, the
implementation of format/printf with respect to autoflusing is reasonable if
these new methods are given the same status as println. For this class, we
must update the specification of PrintWriter to include format/printf in the
list of methods which autoflush. For completeness, we should also add
documentation to format/printf indicating that they autoflush.
Note that for PrintWriter it's hard to achieve the idea-world result of making
PrintWriter.printf("Hello%n") the same as PrintWriter.println("Hello") because
we do that, one can also ask why PrintWriter.print("Hello\n") doesn't autoflush
the same way. Unfortunately, the latter is existing behaviour which we can not
change due to compatibilty constraints.
For the new Print{Stream,Writer} contructors, I have verified that the setting
of autoflush is consistent with pre-existing constructors which don't take
the autoflush parameter. The current implementation matches the specification.
No changes are necessary in this area.
-- iag@sfbay 2004-06-20
|