Issue#22 Splited fileWithMD5 , improved reader

This commit is contained in:
Didier Clermonté 2016-06-19 12:09:10 +02:00
parent 3ef3009ea0
commit 72517c89f3
2 changed files with 41 additions and 51 deletions

View File

@ -136,7 +136,7 @@ public class SibaManager
try try
{ {
String md5String = SibaUtils.loadMD5Sum(choosenFile); String md5String = SibaUtils.loadMD5Sum(choosenFile);
File fileToCheck1 = SibaUtils.loadFileToCheck(choosenFile); File fileToCheck1 = SibaUtils.readFileNameToCheck(choosenFile);
if (StringUtils.equals(md5String, SibaUtils.md5(fileToCheck1))) if (StringUtils.equals(md5String, SibaUtils.md5(fileToCheck1)))
{ {
result = true; result = true;

View File

@ -19,6 +19,7 @@
*/ */
package org.dclermonte.siba.model; package org.dclermonte.siba.model;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileReader; import java.io.FileReader;
@ -32,46 +33,6 @@ import org.apache.commons.compress.utils.IOUtils;
public class SibaUtils public class SibaUtils
{ {
/**
*
* @param choosenFile
* @return
* @throws IOException
*/
public static File loadFileToCheck(final File choosenFile) throws IOException
{
File result = null;
if (choosenFile.exists() && (choosenFile.length() > 32))
{
FileReader fileReader = new FileReader(choosenFile);
// BufferedReader bufferedReader = new BufferedReader(fileReader);
// String line = bufferedReader.readLine();
char[] fileToCheck = new char[(int) (choosenFile.length()) - 32];
fileReader.read();
fileReader.skip(32);
String fileNameToString = new String();
for (int index = 36; index < (choosenFile.length() + 2); index++)
{
fileToCheck[index - 36] = (char) fileReader.read();
fileNameToString = fileNameToString + fileToCheck[index - 36];
}
fileReader.close();
if (choosenFile.isAbsolute())
{
result = new File(choosenFile.getParent() + "/" + fileNameToString);
}
else
{
String path = System.getProperty("user.dir");
result = new File(path + "/" + fileNameToString);
}
}
//
return result;
}
/** /**
* *
* @param choosenFile * @param choosenFile
@ -80,23 +41,18 @@ public class SibaUtils
*/ */
public static String loadMD5Sum(final File choosenFile) throws IOException public static String loadMD5Sum(final File choosenFile) throws IOException
{ {
String result = ""; String result;
result = "";
if (choosenFile.exists() && (choosenFile.length() > 32)) if (choosenFile.exists() && (choosenFile.length() > 32))
{ {
FileReader fileReader = new FileReader(choosenFile); FileReader fileReader = new FileReader(choosenFile);
char[] md5 = new char[32]; BufferedReader bufferedReader = new BufferedReader(fileReader);
byte[] md5byte = new byte[32]; String line = bufferedReader.readLine();
for (int index = 0; index < 32; index++) result = line.substring(0, 32);
{
md5[index] = (char) fileReader.read();
md5byte[index] = (byte) md5[index];
result = result + md5[index];
}
fileReader.close(); fileReader.close();
} }
//
// //
return result; return result;
} }
@ -151,6 +107,40 @@ public class SibaUtils
return result; return result;
} }
/**
*
* @param choosenFile
* @return
* @throws IOException
*/
public static File readFileNameToCheck(final File choosenFile) throws IOException
{
File result;
result = null;
if (choosenFile.exists() && (choosenFile.length() > 32))
{
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 = new File(choosenFile.getParent() + "/" + fileNameToString);
}
else
{
String path = System.getProperty("user.dir");
result = new File(path + "/" + fileNameToString);
}
}
//
return result;
}
/** /**
* *
* @param fileToSave * @param fileToSave