do the same as FileUtils.copyFile do

This commit is contained in:
Olivier Lamy 2014-04-16 19:48:53 +10:00
parent ec1e655c9d
commit 65bcbc9d45
3 changed files with 21 additions and 12 deletions

View File

@ -37,6 +37,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.concurrent.atomic.AtomicInteger;
//import org.apache.commons.io.IOUtils;
@ -90,7 +91,8 @@ public class DefaultFileLockManagerTest
try
{
lock.getFile().delete();
Files.copy( largeJar.toPath(), lock.getFile().toPath() );
Files.copy( largeJar.toPath(), lock.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES );
}
finally
{
@ -108,7 +110,8 @@ public class DefaultFileLockManagerTest
try
{
lock.getFile().delete();
Files.copy( largeJar.toPath(), lock.getFile().toPath() );
Files.copy( largeJar.toPath(), lock.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES );
}
finally
{
@ -144,7 +147,8 @@ public class DefaultFileLockManagerTest
try
{
lock.getFile().delete();
Files.copy( largeJar.toPath(), lock.getFile().toPath() );
Files.copy( largeJar.toPath(), lock.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES );
}
finally
{
@ -162,7 +166,8 @@ public class DefaultFileLockManagerTest
try
{
lock.getFile().delete();
Files.copy( largeJar.toPath(), lock.getFile().toPath() );
Files.copy( largeJar.toPath(), lock.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES );
}
finally
{
@ -179,8 +184,7 @@ public class DefaultFileLockManagerTest
Lock lock = fileLockManager.readFileLock( this.file );
try
{
Files.copy( lock.getFile().toPath(),
new FileOutputStream( File.createTempFile( "foo", ".jar" ) ) );
Files.copy( lock.getFile().toPath(), new FileOutputStream( File.createTempFile( "foo", ".jar" ) ) );
}
finally
{
@ -198,7 +202,8 @@ public class DefaultFileLockManagerTest
try
{
lock.getFile().delete();
Files.copy( largeJar.toPath(), lock.getFile().toPath() );
Files.copy( largeJar.toPath(), lock.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES );
}
finally
{
@ -233,7 +238,8 @@ public class DefaultFileLockManagerTest
try
{
lock.getFile().delete();
Files.copy( largeJar.toPath(), lock.getFile().toPath() );
Files.copy( largeJar.toPath(), lock.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES );
}
finally
{
@ -250,8 +256,7 @@ public class DefaultFileLockManagerTest
Lock lock = fileLockManager.readFileLock( this.file );
try
{
Files.copy( lock.getFile().toPath(),
new FileOutputStream( File.createTempFile( "foo", ".jar" ) ) );
Files.copy( lock.getFile().toPath(), new FileOutputStream( File.createTempFile( "foo", ".jar" ) ) );
}
finally
{

View File

@ -90,6 +90,7 @@ import javax.ws.rs.core.Response;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -530,7 +531,8 @@ public class DefaultRepositoriesService
private void copyFile( File sourceFile, File targetPath, String targetFilename, boolean fixChecksums )
throws IOException
{
Files.copy( sourceFile.toPath(), new File( targetPath, targetFilename ).toPath() );
Files.copy( sourceFile.toPath(), new File( targetPath, targetFilename ).toPath(), StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES );
if ( fixChecksums )
{

View File

@ -70,6 +70,7 @@ import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -577,7 +578,8 @@ public class DefaultFileUploadService
throws IOException
{
Files.copy( sourceFile.toPath(), new File( targetPath, targetFilename ).toPath() );
Files.copy( sourceFile.toPath(), new File( targetPath, targetFilename ).toPath(), StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES );
if ( fixChecksums )
{