Skip to content

Commit 49a1662

Browse files
authored
Merge pull request #12 from headcrashing/offloading
offloading file copy work to operating system allows potential speedup
2 parents 513b3a8 + 8b16d8b commit 49a1662

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/main/java/org/codehaus/plexus/util/FileUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,16 @@ public static void copyFile( final File source, final File destination )
11041104

11051105
private static void doCopyFile( File source, File destination )
11061106
throws IOException
1107+
{
1108+
// offload to operating system if supported
1109+
if ( Java7Detector.isJava7() )
1110+
doCopyFileUsingNewIO( source, destination );
1111+
else
1112+
doCopyFileUsingLegacyIO( source, destination );
1113+
}
1114+
1115+
private static void doCopyFileUsingLegacyIO( File source, File destination )
1116+
throws IOException
11071117
{
11081118
FileInputStream fis = null;
11091119
FileOutputStream fos = null;
@@ -1141,6 +1151,12 @@ private static void doCopyFile( File source, File destination )
11411151
}
11421152
}
11431153

1154+
private static void doCopyFileUsingNewIO( File source, File destination )
1155+
throws IOException
1156+
{
1157+
NioFiles.copy( source, destination );
1158+
}
1159+
11441160
/**
11451161
* Copy file from source to destination only if source timestamp is later than the destination timestamp.
11461162
* The directories up to <code>destination</code> will be created if they don't already exist.

0 commit comments

Comments
 (0)