Issue#22 improved createMD5File method in SibaUtils
This commit is contained in:
parent
163851eb09
commit
74358afc3b
|
@ -103,7 +103,7 @@ public class SibaManager
|
|||
out = new TarArchiveOutputStream(gzipOutputStream);
|
||||
SibaUtils.tarDirectoryTree(fileToSave, out);
|
||||
out.close();
|
||||
SibaUtils.prepareMD5File(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5");
|
||||
SibaUtils.createMD5File(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5");
|
||||
}
|
||||
}
|
||||
catch (IOException ioExceptionBackup)
|
||||
|
|
|
@ -39,23 +39,53 @@ 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
|
||||
/**
|
||||
*
|
||||
* This method Generate the file with MD5.
|
||||
*
|
||||
* @param inputDirectory
|
||||
* @param target
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws NoSuchAlgorithmException
|
||||
*/
|
||||
public static File createMD5File(final File inputDirectory, final String target)
|
||||
throws IOException, NoSuchAlgorithmException
|
||||
{
|
||||
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();
|
||||
String md5 = SibaUtils.md5(inputDirectory);
|
||||
String fileName = inputDirectory.getName();
|
||||
result = createMD5File(md5, fileName, target);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public static File createMD5File(final String md5, final String fileName, final String target) throws IOException
|
||||
{
|
||||
File result;
|
||||
FileWriter fileWriter;
|
||||
fileWriter = null;
|
||||
try
|
||||
{
|
||||
result = new File(target);
|
||||
fileWriter = new FileWriter(result);
|
||||
fileWriter.write(md5);
|
||||
String newLine = System.getProperty("line.separator");
|
||||
fileWriter.append(" ");
|
||||
fileWriter.append(fileName);
|
||||
fileWriter.append(newLine);
|
||||
fileWriter.close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(fileWriter);
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param choosenFile
|
||||
|
@ -65,20 +95,27 @@ public class SibaUtils
|
|||
public static String loadMD5Sum(final File choosenFile) throws IOException
|
||||
{
|
||||
String result;
|
||||
|
||||
if (choosenFile.exists() && (choosenFile.length() > 32))
|
||||
FileReader fileReader;
|
||||
fileReader = null;
|
||||
try
|
||||
{
|
||||
FileReader fileReader = new FileReader(choosenFile);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
String line = bufferedReader.readLine();
|
||||
result = line.substring(0, 32);
|
||||
fileReader.close();
|
||||
if (choosenFile.exists() && (choosenFile.length() > 32))
|
||||
{
|
||||
fileReader = new FileReader(choosenFile);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
String line = bufferedReader.readLine();
|
||||
result = line.substring(0, 32);
|
||||
fileReader.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
finally
|
||||
{
|
||||
result = "";
|
||||
IOUtils.closeQuietly(fileReader);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
@ -135,29 +172,6 @@ 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
|
||||
|
@ -167,30 +181,38 @@ public class SibaUtils
|
|||
public static File readFileNameToCheck(final File choosenFile) throws IOException
|
||||
{
|
||||
File result;
|
||||
|
||||
// result = null;
|
||||
if (choosenFile.exists() && (choosenFile.length() > 32))
|
||||
FileReader fileReader;
|
||||
fileReader = null;
|
||||
try
|
||||
{
|
||||
FileReader fileReader = new FileReader(choosenFile);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
String line = bufferedReader.readLine();
|
||||
String fileNameToString = new String();
|
||||
fileNameToString = line.substring(33);
|
||||
fileReader.close();
|
||||
if (choosenFile.isAbsolute())
|
||||
// result = null;
|
||||
if (choosenFile.exists() && (choosenFile.length() > 32))
|
||||
{
|
||||
result = new File(choosenFile.getParent() + "/" + fileNameToString);
|
||||
fileReader = new FileReader(choosenFile);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
String line = bufferedReader.readLine();
|
||||
String fileNameToString = new String();
|
||||
fileNameToString = line.substring(33);
|
||||
fileReader.close();
|
||||
if (choosenFile.isAbsolute())
|
||||
{
|
||||
result = new File(choosenFile.getParent() + "/" + fileNameToString);
|
||||
}
|
||||
else
|
||||
{
|
||||
String path = System.getProperty("user.dir");
|
||||
result = new File(path + "/" + fileNameToString);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
String path = System.getProperty("user.dir");
|
||||
result = new File(path + "/" + fileNameToString);
|
||||
result = null;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
finally
|
||||
{
|
||||
result = null;
|
||||
IOUtils.closeQuietly(fileReader);
|
||||
}
|
||||
//
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue