refactored some codes to use FileUtils instead

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@354744 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Edwin L. Punzalan 2005-12-07 07:11:18 +00:00
parent 079aeac314
commit 2b5e09d679
1 changed files with 8 additions and 59 deletions

View File

@ -32,6 +32,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import org.codehaus.plexus.util.FileUtils;
/**
* @TODO
@ -235,8 +236,8 @@ public class AbstractChecksumArtifactReporterTest
String url = repository.getBasedir() + "/" + filename + "." + type;
boolean copied = copyFile( url, repoUrl + relativePath + filename + "." + type );
//FileUtils.copyFile( new File( url ), new File( repoUrl + relativePath + filename + "." + type ) );
//boolean copied = copyFile( url, repoUrl + relativePath + filename + "." + type );
FileUtils.copyFile( new File( url ), new File( repoUrl + relativePath + filename + "." + type ) );
//System.out.println( "META FILE COPIED ---->>> " + copied );
//Create md5 and sha-1 checksum files..
@ -359,40 +360,6 @@ public class AbstractChecksumArtifactReporterTest
return output.toUpperCase();
}
/**
* Copy created metadata file to the repository.
* @param srcUrl
* @param destUrl
* @return
*/
private boolean copyFile( String srcUrl, String destUrl )
{
try
{
//source file
File src = new File( srcUrl );
//destination file
File dest = new File( destUrl );
InputStream in = new FileInputStream( src );
OutputStream out = new FileOutputStream( dest );
byte[] buf = new byte[1024];
int len;
while ( ( len = in.read( buf ) ) > 0 )
{
out.write( buf, 0, len );
}
in.close();
out.close();
}
catch ( Exception e )
{
return false;
}
return true;
}
/**
* Delete the test directory created in the repository.
* @param dirname The directory to be deleted.
@ -402,32 +369,14 @@ public class AbstractChecksumArtifactReporterTest
{
boolean b = false;
if ( dir.isDirectory() == true )
try
{
if ( dir.listFiles().length > 0 )
{
File[] files = dir.listFiles();
for ( int i = 0; i < files.length; i++ )
{
b = this.deleteTestDirectory( files[i] );
//check if this is the last file in the directory
//delete the parent file
if((i == (files.length - 1)) && b == true){
String[] split = dir.getAbsolutePath().split("/repository");
if(!files[i].getParent().equals(split[0] + "/repository")){
b = this.deleteTestDirectory(new File(files[i].getParent()));
}
}
}
}else{
b = dir.delete();
}
FileUtils.deleteDirectory( dir );
b = true;
}
else
catch ( IOException ioe )
{
b = dir.delete();
ioe.printStackTrace();
}
return b;