Issue#22 Refactored SibaManager.createMD5File

This commit is contained in:
Didier Clermonté 2016-06-22 22:54:56 +02:00
parent f3bcf8e9f7
commit d7eba49221
2 changed files with 42 additions and 30 deletions

View File

@ -22,7 +22,6 @@ package org.dclermonte.siba.model;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.security.NoSuchAlgorithmException;
@ -104,7 +103,7 @@ public class SibaManager
out = new TarArchiveOutputStream(gzipOutputStream);
SibaUtils.tarDirectoryTree(fileToSave, out);
out.close();
createMD5File(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5");
SibaUtils.prepareMD5File(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5");
}
}
catch (IOException ioExceptionBackup)
@ -161,32 +160,4 @@ public class SibaManager
return result;
}
/**
*
* This method Generate the file with MD5.
*
* @param directoryToSave
* @param destination
* @return
* @throws IOException
* @throws NoSuchAlgorithmException
*/
public static File createMD5File(final File directoryToSave, final String destination)
throws IOException, NoSuchAlgorithmException
{
File result;
result = new File(destination);
FileWriter fileWriter = new FileWriter(result);
fileWriter.write(SibaUtils.md5(directoryToSave));
String newLine = System.getProperty("line.separator");
fileWriter.append(" ");
fileWriter.append(directoryToSave.getName());
fileWriter.append(newLine);
fileWriter.close();
//
return result;
}
}

View File

@ -23,6 +23,7 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -38,6 +39,23 @@ import org.apache.commons.compress.utils.IOUtils;
*/
public class SibaUtils
{
public static File createMD5File(final String md5, final String fileName, final String target) throws IOException
{
File result;
result = new File(target);
FileWriter fileWriter = new FileWriter(result);
fileWriter.write(md5);
String newLine = System.getProperty("line.separator");
fileWriter.append(" ");
fileWriter.append(fileName);
fileWriter.append(newLine);
fileWriter.close();
//
return result;
}
/**
*
* @param choosenFile
@ -117,6 +135,29 @@ public class SibaUtils
return result;
}
/**
*
* This method Generate the file with MD5.
*
* @param directoryToCheck
* @param destination
* @return
* @throws IOException
* @throws NoSuchAlgorithmException
*/
public static File prepareMD5File(final File directoryToCheck, final String destination)
throws IOException, NoSuchAlgorithmException
{
File result;
String md5 = SibaUtils.md5(directoryToCheck);
String fileName = directoryToCheck.getName();
result = createMD5File(md5, fileName, destination);
//
return result;
}
/**
*
* @param choosenFile