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

2016-11-24 Thread Patrick Reinhart
Any sponsor for this?

> Am 23.11.2016 um 21:53 schrieb Patrick Reinhart :
> 
> Hi Stephen,
> 
> I changed the webrev accordingly:
> 
> http://cr.openjdk.java.net/~reinhapa/reviews/8167648/webrev.00
> 
> -Patrick
> 
>> Am 23.11.2016 um 14:45 schrieb Stephen Colebourne :
>> 
>> Returning the writer was my intention. I also intended it to return a
>> new instance, to avoid changing the variable from final to non-final.
>> Stephen
>> 
> 



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

2016-11-23 Thread Patrick Reinhart
Hi Stephen,

I changed the webrev accordingly:

http://cr.openjdk.java.net/~reinhapa/reviews/8167648/webrev.00

-Patrick

> Am 23.11.2016 um 14:45 schrieb Stephen Colebourne :
> 
> Returning the writer was my intention. I also intended it to return a
> new instance, to avoid changing the variable from final to non-final.
> Stephen
> 



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

2016-11-23 Thread Stephen Colebourne
Returning the writer was my intention. I also intended it to return a
new instance, to avoid changing the variable from final to non-final.
Stephen


On 23 November 2016 at 13:35, Jonathan Bluett-Duncan
 wrote:
> Hi Patrick,
>
> Have you considered making `withAutoFlush()` return the `PrintWriter`
> itself, allowing fluent code snippets like the following?
>
> ```
> PrintWriter writer = new PrintWriter(new File("path/to/file.txt"),
> StandardCharsets.UTF_8).withAutoFlush();
> ```
>
> Kind regards,
> Jonathan
>
> On 23 November 2016 at 13:09, Patrick Reinhart  wrote:
>>
>> Added those new public constructors:
>>
>> PrintWriter(OutputStream, Charset)
>> PrintWriter(File, Charset)
>> withAutoFlush()
>>
>> Also added a new private constructor:
>>
>> PrintWriter(OutputStream, Charset, boolean)
>>
>> and rewired the OutputStream constructor calls to this private
>> constructor.
>>
>>
>> Here's the webrev:
>>
>> http://cr.openjdk.java.net/~reinhapa/reviews/8167648/webrev.00
>>
>>
>> -Patrick
>
>


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

2016-11-23 Thread Patrick Reinhart

On 2016-11-23 14:35, Jonathan Bluett-Duncan wrote:

Hi Patrick,

Have you considered making `withAutoFlush()` return the `PrintWriter`
itself, allowing fluent code snippets like the following?

```
PrintWriter writer = new PrintWriter(new File("path/to/file.txt"),
StandardCharsets.UTF_8).withAutoFlush();
```



Good point. I taught about it, but it somehow got lost on the way of 
re-wiring the constructors... :-)


Just updated the webrev


-Patrick


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

2016-11-23 Thread Jonathan Bluett-Duncan
Hi Patrick,

Have you considered making `withAutoFlush()` return the `PrintWriter`
itself, allowing fluent code snippets like the following?

```
PrintWriter writer = new PrintWriter(new File("path/to/file.txt"),
StandardCharsets.UTF_8).withAutoFlush();
```

Kind regards,
Jonathan

On 23 November 2016 at 13:09, Patrick Reinhart  wrote:

> Added those new public constructors:
>
> PrintWriter(OutputStream, Charset)
> PrintWriter(File, Charset)
> withAutoFlush()
>
> Also added a new private constructor:
>
> PrintWriter(OutputStream, Charset, boolean)
>
> and rewired the OutputStream constructor calls to this private constructor.
>
>
> Here's the webrev:
>
> http://cr.openjdk.java.net/~reinhapa/reviews/8167648/webrev.00
>
>
> -Patrick
>


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

2016-11-23 Thread Patrick Reinhart

Added those new public constructors:

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

Also added a new private constructor:

PrintWriter(OutputStream, Charset, boolean)

and rewired the OutputStream constructor calls to this private 
constructor.



Here's the webrev:

http://cr.openjdk.java.net/~reinhapa/reviews/8167648/webrev.00


-Patrick


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

2016-11-23 Thread Patrick Reinhart

Hi Stephen,

On 2016-11-23 12:04, Stephen Colebourne wrote:



Perhaps a method withAutoFlush(boolean) could reduce the number of


To make that work, we would have to make the boolean field "autoFlush" 
writeable. Also the auto flush behaviour could be changed at any time. I 
would then prefer to only have something like a one-way-street as this:


withAutoFlush() intentionally no argument to only change it to enabled.



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




I would think, this would be a good change.

-Patrick


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

2016-11-23 Thread Stephen Colebourne
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  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.UTF_8));
>>
>>
>>
>> On the other hand then the next request will be to add constructors
>> also to specify autoflush and so on...
>>
>> -Patrick


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

2016-11-23 Thread Patrick Reinhart

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.UTF_8));



On the other hand then the next request will be to add constructors
also to specify autoflush and so on...

-Patrick