You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2021/11/02 06:49:17 UTC

[GitHub] [commons-io] wodencafe opened a new pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

wodencafe opened a new pull request #296:
URL: https://github.com/apache/commons-io/pull/296


   This pull request simplifies org.apache.commons.io.output.FileWriterWithEncoding by removing the decorated object and extending org.apache.commons.io.output.ProxyWriter directly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow commented on a change in pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r743203274



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -59,7 +57,7 @@
      * @return the initialized writer
      * @throws IOException if an error occurs
      */
-    private static Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {
+    private static final Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {

Review comment:
       This one is not really necessary @wodencafe ? `initWriter` is already private, so making it `final` won't change much for internal/external devs?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow edited a comment on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow edited a comment on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958613424


   @wodencafe we would also need a JIRA for this, could you create one? I think we will be able to make `FilterWriterWithEncoding` extend `ProxyWriter`. But in case we find a roadblock somewhere and we are not able to make `FileWriterWithEncoding` extend `ProxyWriter`, we should be able to at least improve the existing comment in the code explaining better why that's not possible (just in case it's indeed not possible :+1: )
   
   Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow commented on a change in pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r741530222



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -46,9 +46,53 @@
  *
  * @since 1.4
  */
-public class FileWriterWithEncoding extends Writer {
-    // Cannot extend ProxyWriter, as requires writer to be
-    // known when super() is called
+public class FileWriterWithEncoding extends ProxyWriter {
+
+    private static final Writer NULL_WRITER = new Writer() {

Review comment:
       Just saw your comment about the `Writer.nullWriter()`, I guess that's where you got the name from :+1: no need to change it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on a change in pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r743379795



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -59,7 +57,7 @@
      * @return the initialized writer
      * @throws IOException if an error occurs
      */
-    private static Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {
+    private static final Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {

Review comment:
       I usually do this out of habit, but after doing some research it seems that there is no functional difference for adding the `final` modifier to a private static nested class. It has been removed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] garydgregory commented on pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-961244505


   FYI: I should be able to review this over the weekend.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow commented on a change in pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r743203274



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -59,7 +57,7 @@
      * @return the initialized writer
      * @throws IOException if an error occurs
      */
-    private static Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {
+    private static final Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {

Review comment:
       This one is not really necessary @wodencafe ? `initWriter` is already private, so making it `final` won't change much for internal/external devs?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-957649989


   @garydgregory Now the FileWriterWithEncoding extends ProxyWriter, and the actual Proxy class for writing is stored in ProxyWriter rather than inside FileWriterWithEncoding itself. We can probably also get rid of the write methods in FileWriterWithEncoding, and just let them delegate to the superclass ProxyWriter. This will reduce the amount of code significantly, but also the JavaDoc for those methods will be inherited from ProxyWriter.
   
   Also starting with Java 11, there is the static Writer.nullWriter(), which can be used instead of the anonymous class instance NULL_WRITER (whenever Apache Commons IO upgrades minimum version to Java 11).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow commented on a change in pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r741586353



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -245,7 +240,7 @@ public FileWriterWithEncoding(final String fileName, final String charsetName, f
      */

Review comment:
       @wodencafe do we need to override the methods below? Could we just use the parent methods directly?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] garydgregory commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-957249912


   How is this simpler when there is _more_ code?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow edited a comment on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow edited a comment on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958613424


   @wodencafe we would also need a JIRA for this, could you create one? I think we will be able to make `FilterWriterWithEncoding` extend `ProxyWriter`. But in case we find a roadblock somewhere and we are not able to make `FileWriterWithEncoding` extend `ProxyWriter`, we should be able to at least improve the existing comment in the code explaining better why that's not possible (just in case it's indeed not possible :+1: )
   
   Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958613424






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] garydgregory commented on pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-961244505


   FYI: I should be able to review this over the weekend.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958602720






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on a change in pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r741647754



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -245,7 +240,7 @@ public FileWriterWithEncoding(final String fileName, final String charsetName, f
      */

Review comment:
       Good point, we should just let the super class handle it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow edited a comment on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow edited a comment on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958613424


   @wodencafe we would also need a JIRA for this, could you create one? I think we will be able to make `FilterWriterWithEncoding` extend `ProxyWriter`. But in case we find a roadblock somewhere and we are not able to make `FileWriterWithEncoding` extend `ProxyWriter`, we should be able to at least improve the existing comment in the code explaining better why that's not possible (just in case it's indeed not possible :+1: )
   
   Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow commented on a change in pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r743203274



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -59,7 +57,7 @@
      * @return the initialized writer
      * @throws IOException if an error occurs
      */
-    private static Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {
+    private static final Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {

Review comment:
       This one is not really necessary @wodencafe ? `initWriter` is already private, so making it `final` won't change much for internal/external devs?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow commented on a change in pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r741586353



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -245,7 +240,7 @@ public FileWriterWithEncoding(final String fileName, final String charsetName, f
      */

Review comment:
       @wodencafe do we need to override the methods below? Could we just use the parent methods directly?

##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -245,7 +240,7 @@ public FileWriterWithEncoding(final String fileName, final String charsetName, f
      */

Review comment:
       @wodencafe do we need to override the methods below? Could we just use the parent methods directly?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on a change in pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r741647754



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -245,7 +240,7 @@ public FileWriterWithEncoding(final String fileName, final String charsetName, f
      */

Review comment:
       Good point, we should just let the super class handle it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-961346035






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] garydgregory commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-957249912


   How is this simpler when there is _more_ code?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe edited a comment on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe edited a comment on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-957649989


   @garydgregory Now the FileWriterWithEncoding extends ProxyWriter, and the actual Proxy class instance for writing (OutputStreamWriter) is stored in ProxyWriter rather than inside FileWriterWithEncoding itself. We can probably also get rid of the write methods in FileWriterWithEncoding, and just let them delegate to the superclass ProxyWriter. This will reduce the amount of code significantly, but also the JavaDoc for those methods will be inherited from ProxyWriter. 
   
   Also, with regard to the anonymous class instance of Writer, NULL_WRITER:
   starting with Java 11, there is the static method Writer.nullWriter(), which can be used instead of the anonymous class instance NULL_WRITER (whenever Apache Commons IO upgrades minimum version to Java 11).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow commented on a change in pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r741526857



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -46,9 +46,53 @@
  *
  * @since 1.4
  */
-public class FileWriterWithEncoding extends Writer {
-    // Cannot extend ProxyWriter, as requires writer to be
-    // known when super() is called
+public class FileWriterWithEncoding extends ProxyWriter {
+
+    private static final Writer NULL_WRITER = new Writer() {

Review comment:
       Not sure if it's handling `null`s, or being used when some value is `null`. But maybe `NOOP_WRITER` would be a better name?

##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -160,7 +209,11 @@ public FileWriterWithEncoding(final File file, final String charsetName) throws
      * @throws IOException in case of an I/O error.
      */
     public FileWriterWithEncoding(final File file, final String charsetName, final boolean append) throws IOException {
-        this.out = initWriter(file, charsetName, append);
+        super(NULL_WRITER);
+
+        super.out = initWriter(file, charsetName, append);

Review comment:
       Ah, I think now I understand this pull request.
   
   @wodencafe I think we pass the `NULL_WRITER` to the parent `ProxyWriter` as a way to give it a valid object. But in reality, that `NULL_WRITER` is then replaced here when we call `super.out = ....`.
   
   While I guess that would work, but not sure if modifying setting `super.out` twice (once after the `super(NULL_WRITER)`, then here :point_up: ) would be the best approach.

##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -46,9 +46,53 @@
  *
  * @since 1.4
  */
-public class FileWriterWithEncoding extends Writer {
-    // Cannot extend ProxyWriter, as requires writer to be
-    // known when super() is called
+public class FileWriterWithEncoding extends ProxyWriter {
+
+    private static final Writer NULL_WRITER = new Writer() {

Review comment:
       Just saw your comment about the `Writer.nullWriter()`, I guess that's where you got the name from :+1: no need to change it.

##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -245,7 +240,7 @@ public FileWriterWithEncoding(final String fileName, final String charsetName, f
      */

Review comment:
       @wodencafe do we need to override the methods below? Could we just use the parent methods directly?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-957649989


   @garydgregory Now the FileWriterWithEncoding extends ProxyWriter, and the actual Proxy class for writing is stored in ProxyWriter rather than inside FileWriterWithEncoding itself. We can probably also get rid of the write methods in FileWriterWithEncoding, and just let them delegate to the superclass ProxyWriter. This will reduce the amount of code significantly, but also the JavaDoc for those methods will be inherited from ProxyWriter.
   
   Also starting with Java 11, there is the static Writer.nullWriter(), which can be used instead of the anonymous class instance NULL_WRITER (whenever Apache Commons IO upgrades minimum version to Java 11).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958427374


   @wodencafe I was curious, and tried the following too before jumping to other PRs:
   
   ```diff
   diff --git a/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java b/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
   index 3d7cfb27..7fbeee23 100644
   --- a/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
   +++ b/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
   @@ -46,10 +46,7 @@
     *
     * @since 1.4
     */
   -public class FileWriterWithEncoding extends Writer {
   -    // Cannot extend ProxyWriter, as requires writer to be
   -    // known when super() is called
   -
   +public class FileWriterWithEncoding extends ProxyWriter {
        /**
         * Initializes the wrapped file writer. Ensure that a cleanup occurs if the writer creation fails.
         *
   @@ -85,9 +82,6 @@ private static Writer initWriter(final File file, final Object encoding, final b
            }
        }
    
   -    /** The writer to decorate. */
   -    private final Writer out;
   -
        /**
         * Constructs a FileWriterWithEncoding with a file encoding.
         *
   @@ -110,7 +104,7 @@ public FileWriterWithEncoding(final File file, final Charset charset) throws IOE
         * @throws IOException in case of an I/O error.
         */
        public FileWriterWithEncoding(final File file, final Charset encoding, final boolean append) throws IOException {
   -        this.out = initWriter(file, encoding, append);
   +        super(initWriter(file, encoding, append));
        }
    
        /**
   @@ -135,7 +129,7 @@ public FileWriterWithEncoding(final File file, final CharsetEncoder charsetEncod
         * @throws IOException in case of an I/O error.
         */
        public FileWriterWithEncoding(final File file, final CharsetEncoder charsetEncoder, final boolean append) throws IOException {
   -        this.out = initWriter(file, charsetEncoder, append);
   +        super(initWriter(file, charsetEncoder, append));
        }
    
        /**
   @@ -160,7 +154,7 @@ public FileWriterWithEncoding(final File file, final String charsetName) throws
         * @throws IOException in case of an I/O error.
         */
        public FileWriterWithEncoding(final File file, final String charsetName, final boolean append) throws IOException {
   -        this.out = initWriter(file, charsetName, append);
   +        super(initWriter(file, charsetName, append));
        }
    
        /**
   ```
   
   I think it achieves something similar to what you are suggesting here, but without the extra internal class? I haven't tested it, and haven't worked on IO lately, so other committers would have to take a look at it too. But WDYT?
   
   Bruno


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-961346035


   Thank you @garydgregory and @kinow for the assistance with this pull request.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on a change in pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r743379795



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -59,7 +57,7 @@
      * @return the initialized writer
      * @throws IOException if an error occurs
      */
-    private static Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {
+    private static final Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {

Review comment:
       I usually do this out of habit, but after doing some research it seems that there is no functional difference for adding the `final` modifier to a private static nested class. It has been removed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-961615200


   @kinow The commits have been squashed and and updated as per your request. Thank you for the help!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] data443-cboyd removed a comment on pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
data443-cboyd removed a comment on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-961249815


   Thank you @garydgregory and @kinow for the assistance with this pull request.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] garydgregory commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-957249912


   How is this simpler when there is _more_ code?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958670115


   @kinow No problem, here is the associated JIRA ticket: https://issues.apache.org/jira/browse/IO-756


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958613424


   @wodencafe we would also need a JIRA for this, could you create one? I think we will be able to make `FilterWriterWithEncoding` extend `ProxyWriter`. But in case we find a roadblock somewhere and we are not able to make `FileWriterWithEncoding` extend `ProxyWriter`, we should be able to at least improve the existing comment in the code explaining better why that's not possible (just in case it's indeed no possible :+1: )
   
   Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow edited a comment on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow edited a comment on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958613424


   @wodencafe we would also need a JIRA for this, could you create one? I think we will be able to make `FilterWriterWithEncoding` extend `ProxyWriter`. But in case we find a roadblock somewhere and we are not able to make `FileWriterWithEncoding` extend `ProxyWriter`, we should be able to at least improve the existing comment in the code explaining better why that's not possible (just in case it's indeed not possible :+1: )
   
   Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-961346035






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958427374






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958602720






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] data443-cboyd commented on pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
data443-cboyd commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-961249815


   Thank you @garydgregory and @kinow for the assistance with this pull request.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958611431


   Hello again @kinow , just wanted to let you know that the changes have been made.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on a change in pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r741647754



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -245,7 +240,7 @@ public FileWriterWithEncoding(final String fileName, final String charsetName, f
      */

Review comment:
       Good point, we should just let the super class handle it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe edited a comment on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe edited a comment on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-957649989


   @garydgregory Now the FileWriterWithEncoding extends ProxyWriter, and the actual Proxy class instance for writing (OutputStreamWriter) is stored in ProxyWriter rather than inside FileWriterWithEncoding itself. We can probably also get rid of the write methods in FileWriterWithEncoding, and just let them delegate to the superclass ProxyWriter. This will reduce the amount of code significantly, but also the JavaDoc for those methods will be inherited from ProxyWriter. 
   
   Also, with regard to the anonymous class instance of Writer, NULL_WRITER:
   starting with Java 11, there is the static method Writer.nullWriter(), which can be used instead of the anonymous class instance NULL_WRITER (whenever Apache Commons IO upgrades minimum version to Java 11).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on a change in pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r741647754



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -245,7 +240,7 @@ public FileWriterWithEncoding(final String fileName, final String charsetName, f
      */

Review comment:
       Good point, we should just let the super class handle it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] data443-cboyd removed a comment on pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
data443-cboyd removed a comment on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-961249815


   Thank you @garydgregory and @kinow for the assistance with this pull request.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] data443-cboyd removed a comment on pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
data443-cboyd removed a comment on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-961249815


   Thank you @garydgregory and @kinow for the assistance with this pull request.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] garydgregory merged pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
garydgregory merged pull request #296:
URL: https://github.com/apache/commons-io/pull/296


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] data443-cboyd commented on pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
data443-cboyd commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-961249815


   Thank you @garydgregory and @kinow for the assistance with this pull request.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on a change in pull request #296: IO-756: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r743379795



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -59,7 +57,7 @@
      * @return the initialized writer
      * @throws IOException if an error occurs
      */
-    private static Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {
+    private static final Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {

Review comment:
       I usually do this out of habit, but after doing some research it seems that there is no functional difference for adding the `final` modifier to a private static nested class. It has been removed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-957649989


   @garydgregory Now the FileWriterWithEncoding extends ProxyWriter, and the actual Proxy class for writing is stored in ProxyWriter rather than inside FileWriterWithEncoding itself. We can probably also get rid of the write methods in FileWriterWithEncoding, and just let them delegate to the superclass ProxyWriter. This will reduce the amount of code significantly, but also the JavaDoc for those methods will be inherited from ProxyWriter.
   
   Also starting with Java 11, there is the static Writer.nullWriter(), which can be used instead of the anonymous class instance NULL_WRITER (whenever Apache Commons IO upgrades minimum version to Java 11).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] kinow commented on a change in pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #296:
URL: https://github.com/apache/commons-io/pull/296#discussion_r741526857



##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -46,9 +46,53 @@
  *
  * @since 1.4
  */
-public class FileWriterWithEncoding extends Writer {
-    // Cannot extend ProxyWriter, as requires writer to be
-    // known when super() is called
+public class FileWriterWithEncoding extends ProxyWriter {
+
+    private static final Writer NULL_WRITER = new Writer() {

Review comment:
       Not sure if it's handling `null`s, or being used when some value is `null`. But maybe `NOOP_WRITER` would be a better name?

##########
File path: src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
##########
@@ -160,7 +209,11 @@ public FileWriterWithEncoding(final File file, final String charsetName) throws
      * @throws IOException in case of an I/O error.
      */
     public FileWriterWithEncoding(final File file, final String charsetName, final boolean append) throws IOException {
-        this.out = initWriter(file, charsetName, append);
+        super(NULL_WRITER);
+
+        super.out = initWriter(file, charsetName, append);

Review comment:
       Ah, I think now I understand this pull request.
   
   @wodencafe I think we pass the `NULL_WRITER` to the parent `ProxyWriter` as a way to give it a valid object. But in reality, that `NULL_WRITER` is then replaced here when we call `super.out = ....`.
   
   While I guess that would work, but not sure if modifying setting `super.out` twice (once after the `super(NULL_WRITER)`, then here :point_up: ) would be the best approach.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe edited a comment on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe edited a comment on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-957649989


   @garydgregory Now the FileWriterWithEncoding extends ProxyWriter, and the actual Proxy class instance for writing (OutputStreamWriter) is stored in ProxyWriter rather than inside FileWriterWithEncoding itself. We can probably also get rid of the write methods in FileWriterWithEncoding, and just let them delegate to the superclass ProxyWriter. This will reduce the amount of code significantly, but also the JavaDoc for those methods will be inherited from ProxyWriter. 
   
   Also, with regard to the anonymous class instance of Writer, NULL_WRITER:
   starting with Java 11, there is the static method Writer.nullWriter(), which can be used instead of the anonymous class instance NULL_WRITER (whenever Apache Commons IO upgrades minimum version to Java 11).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-io] wodencafe commented on pull request #296: Update FileWriterWithEncoding to extend ProxyWriter

Posted by GitBox <gi...@apache.org>.
wodencafe commented on pull request #296:
URL: https://github.com/apache/commons-io/pull/296#issuecomment-958602720


   Hi @kinow , thanks for reviewing the code. Actually I think that bottom approach is simpler, I'll give it a try, and update the PR accordingly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org