You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/06/19 14:06:29 UTC

[commons-io] branch master updated: Refactor duplicate code

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 860ed6ba Refactor duplicate code
860ed6ba is described below

commit 860ed6ba033e7b11ea257d1599e4f759d133d805
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jun 19 10:06:24 2022 -0400

    Refactor duplicate code
---
 .../commons/io/output/FilterCollectionWriter.java  | 24 +++++++++++++---------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/output/FilterCollectionWriter.java b/src/main/java/org/apache/commons/io/output/FilterCollectionWriter.java
index 04734574..6bc7d38f 100644
--- a/src/main/java/org/apache/commons/io/output/FilterCollectionWriter.java
+++ b/src/main/java/org/apache/commons/io/output/FilterCollectionWriter.java
@@ -85,25 +85,25 @@ public class FilterCollectionWriter extends Writer {
 
     @Override
     public Writer append(final char c) throws IOException {
-        IOConsumer.forEachIndexed(writers(), w -> w.append(c));
+        forEachWriter(w -> w.append(c));
         return this;
     }
 
     @Override
     public Writer append(final CharSequence csq) throws IOException {
-        IOConsumer.forEachIndexed(writers(), w -> w.append(csq));
+        forEachWriter(w -> w.append(csq));
         return this;
     }
 
     @Override
     public Writer append(final CharSequence csq, final int start, final int end) throws IOException {
-        IOConsumer.forEachIndexed(writers(), w -> w.append(csq, start, end));
+        forEachWriter(w -> w.append(csq, start, end));
         return this;
     }
 
     @Override
     public void close() throws IOException {
-        IOConsumer.forEachIndexed(writers(), Writer::close);
+        forEachWriter(Writer::close);
     }
 
     /**
@@ -113,12 +113,16 @@ public class FilterCollectionWriter extends Writer {
      */
     @Override
     public void flush() throws IOException {
-        IOConsumer.forEachIndexed(writers(), Writer::flush);
+        forEachWriter(Writer::flush);
+    }
+
+    private void forEachWriter(final IOConsumer<Writer> action) throws IOExceptionList {
+        IOConsumer.forEachIndexed(writers(), action);
     }
 
     @Override
     public void write(final char[] cbuf) throws IOException {
-        IOConsumer.forEachIndexed(writers(), w -> w.write(cbuf));
+        forEachWriter(w -> w.write(cbuf));
     }
 
     /**
@@ -132,7 +136,7 @@ public class FilterCollectionWriter extends Writer {
      */
     @Override
     public void write(final char[] cbuf, final int off, final int len) throws IOException {
-        IOConsumer.forEachIndexed(writers(), w -> w.write(cbuf, off, len));
+        forEachWriter(w -> w.write(cbuf, off, len));
     }
 
     /**
@@ -142,12 +146,12 @@ public class FilterCollectionWriter extends Writer {
      */
     @Override
     public void write(final int c) throws IOException {
-        IOConsumer.forEachIndexed(writers(), w -> w.write(c));
+        forEachWriter(w -> w.write(c));
     }
 
     @Override
     public void write(final String str) throws IOException {
-        IOConsumer.forEachIndexed(writers(), w -> w.write(str));
+        forEachWriter(w -> w.write(str));
     }
 
     /**
@@ -161,7 +165,7 @@ public class FilterCollectionWriter extends Writer {
      */
     @Override
     public void write(final String str, final int off, final int len) throws IOException {
-        IOConsumer.forEachIndexed(writers(), w -> w.write(str, off, len));
+        forEachWriter(w -> w.write(str, off, len));
     }
 
     private Stream<Writer> writers() {