diff --git a/src/org/dclermonte/siba/model/SibaManager.java b/src/org/dclermonte/siba/model/SibaManager.java index bbb439d..ef73969 100644 --- a/src/org/dclermonte/siba/model/SibaManager.java +++ b/src/org/dclermonte/siba/model/SibaManager.java @@ -136,7 +136,7 @@ public class SibaManager try { String md5String = SibaUtils.loadMD5Sum(choosenFile); - File fileToCheck1 = SibaUtils.loadFileToCheck(choosenFile); + File fileToCheck1 = SibaUtils.readFileNameToCheck(choosenFile); if (StringUtils.equals(md5String, SibaUtils.md5(fileToCheck1))) { result = true; diff --git a/src/org/dclermonte/siba/model/SibaUtils.java b/src/org/dclermonte/siba/model/SibaUtils.java index 3227ec6..7ef312b 100644 --- a/src/org/dclermonte/siba/model/SibaUtils.java +++ b/src/org/dclermonte/siba/model/SibaUtils.java @@ -19,6 +19,7 @@ */ package org.dclermonte.siba.model; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; @@ -32,46 +33,6 @@ import org.apache.commons.compress.utils.IOUtils; 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 @@ -80,23 +41,18 @@ public class SibaUtils */ public static String loadMD5Sum(final File choosenFile) throws IOException { - String result = ""; + String result; + result = ""; if (choosenFile.exists() && (choosenFile.length() > 32)) { FileReader fileReader = new FileReader(choosenFile); - char[] md5 = new char[32]; - byte[] md5byte = new byte[32]; - for (int index = 0; index < 32; index++) - { - md5[index] = (char) fileReader.read(); - md5byte[index] = (byte) md5[index]; - result = result + md5[index]; - } + BufferedReader bufferedReader = new BufferedReader(fileReader); + String line = bufferedReader.readLine(); + result = line.substring(0, 32); fileReader.close(); } - // // return result; } @@ -151,6 +107,40 @@ public class SibaUtils 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