Skip to content

offloading file copy work to operating system allows potential speedup #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/java/org/codehaus/plexus/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,16 @@ public static void copyFile( final File source, final File destination )

private static void doCopyFile( File source, File destination )
throws IOException
{
// offload to operating system if supported
if ( Java7Detector.isJava7() )
doCopyFileUsingNewIO( source, destination );
else
doCopyFileUsingLegacyIO( source, destination );
}

private static void doCopyFileUsingLegacyIO( File source, File destination )
throws IOException
{
FileInputStream fis = null;
FileOutputStream fos = null;
Expand Down Expand Up @@ -1141,6 +1151,12 @@ private static void doCopyFile( File source, File destination )
}
}

private static void doCopyFileUsingNewIO( File source, File destination )
throws IOException
{
NioFiles.copy( source, destination );
}

/**
* Copy file from source to destination only if source timestamp is later than the destination timestamp.
* The directories up to <code>destination</code> will be created if they don't already exist.
Expand Down