olamy commented on a change in pull request #28:
URL: https://github.com/apache/maven-shared-utils/pull/28#discussion_r430111873



##########
File path: src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
##########
@@ -1810,34 +1816,101 @@ public static void copyFile( @Nonnull File from, 
@Nonnull File to, @Nullable Str
                                  @Nullable FilterWrapper[] wrappers, boolean 
overwrite )
         throws IOException
     {
-        if ( wrappers != null && wrappers.length > 0 )
+        if ( wrappers == null || wrappers.length == 0 )
         {
-            
-            if ( encoding == null || encoding.isEmpty() ) 
+            if ( overwrite || to.lastModified() < from.lastModified() )
+            {
+                copyFile( from, to );
+            }
+        }
+        else
+        {
+            if ( encoding == null || encoding.isEmpty() )
             {
                 encoding = Charset.defaultCharset().name();
             }
-            
+
             // buffer so it isn't reading a byte at a time!
             try ( Reader fileReader =
-                new BufferedReader( new InputStreamReader( new 
FileInputStream( from ), encoding ) );
-                            Writer fileWriter = new OutputStreamWriter( new 
FileOutputStream( to ), encoding ) )
+                    new BufferedReader( new InputStreamReader( new 
FileInputStream( from ), encoding ) ) )
             {
-
                 Reader wrapped = fileReader;
                 for ( FilterWrapper wrapper : wrappers )
                 {
                     wrapped = wrapper.getReader( wrapped );
                 }
 
-                IOUtil.copy( wrapped, fileWriter );
-            }
-        }
-        else
-        {
-            if ( to.lastModified() < from.lastModified() || overwrite )
-            {
-                copyFile( from, to );
+                if ( overwrite || !to.exists() )
+                {
+                    try ( Writer fileWriter = new OutputStreamWriter( new 
FileOutputStream( to ), encoding ) )

Review comment:
       what about `Files.newBufferedWriter(  )`

##########
File path: src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
##########
@@ -1810,34 +1816,101 @@ public static void copyFile( @Nonnull File from, 
@Nonnull File to, @Nullable Str
                                  @Nullable FilterWrapper[] wrappers, boolean 
overwrite )
         throws IOException
     {
-        if ( wrappers != null && wrappers.length > 0 )
+        if ( wrappers == null || wrappers.length == 0 )
         {
-            
-            if ( encoding == null || encoding.isEmpty() ) 
+            if ( overwrite || to.lastModified() < from.lastModified() )
+            {
+                copyFile( from, to );
+            }
+        }
+        else
+        {
+            if ( encoding == null || encoding.isEmpty() )
             {
                 encoding = Charset.defaultCharset().name();
             }
-            
+
             // buffer so it isn't reading a byte at a time!
             try ( Reader fileReader =
-                new BufferedReader( new InputStreamReader( new 
FileInputStream( from ), encoding ) );
-                            Writer fileWriter = new OutputStreamWriter( new 
FileOutputStream( to ), encoding ) )
+                    new BufferedReader( new InputStreamReader( new 
FileInputStream( from ), encoding ) ) )

Review comment:
       what about `Files.newBufferedReader(  )`?




----------------------------------------------------------------
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.

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


Reply via email to