RFR: JDK-8167648: java.io.PrintWriter should have PrintWriter((String|File), Charset) constructors (original) (raw)

Stephen Colebourne scolebourne at joda.org
Wed Nov 23 11:04:41 UTC 2016


These are the current constructors:

PrintWriter(Writer) PrintWriter(Writer, boolean) PrintWriter(OutputStream) PrintWriter(OutputStream, boolean) PrintWriter(String) PrintWriter(String, String) PrintWriter(File) PrintWriter(File, String)

These are the annoying missing ones (not all of the possible combinations):

PrintWriter(OutputStream, Charset) PrintWriter(OutputStream, Charset, boolean) PrintWriter(String, Charset) PrintWriter(String, Charset, boolean) PrintWriter(File, Charset) PrintWriter(File, Charset, boolean)

there are other missing Charset methods on FileWriter.

Perhaps a method withAutoFlush(boolean) could reduce the number of constructors? And perhaps the String filename is an anachronism?

Thus, adding these three methods might be enough:

PrintWriter(OutputStream, Charset) PrintWriter(File, Charset) withAutoFlush(boolean)

Stephen

On 23 November 2016 at 09:52, Patrick Reinhart <patrick at reini.net> wrote:

Are there any obligations to add those constructors?

-Patrick On 2016-11-18 10:19, Patrick Reinhart wrote:

I was looking at the existing JDK 9 issues for some simple ones I could solve and found this one. I wanted to know if it makes sense to add additional constructors here?

Now you need to do this: ------------------------ try { new PrintWriter(file, "UTF-8"); } catch (UnsupportedEncodingException e) { // Ignore, this is required to be supported by the JVM. } The same applies also to the String constructor...

Instead the following behaviour is requested: --------------------------------------------- new PrintWriter(file, StandardCharsets.UTF8)); On the other hand then the next request will be to add constructors also to specify autoflush and so on... -Patrick



More information about the core-libs-dev mailing list