mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 19:41:59 -08:00
[Updater] Added support for non-jar files. Some refactoring. Java-doc. Logging.
This commit is contained in:
parent
d4eee79ec1
commit
eae50ffd83
8 changed files with 331 additions and 378 deletions
|
|
@ -4,23 +4,35 @@ import java.io.FileInputStream;
|
|||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
/**
|
||||
* @author Loki
|
||||
*/
|
||||
public class ChechsumHelper {
|
||||
public static byte[] createChecksum(String filename) throws
|
||||
Exception
|
||||
{
|
||||
InputStream fis = new FileInputStream(filename);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
MessageDigest complete = MessageDigest.getInstance("SHA1");
|
||||
int numRead;
|
||||
do {
|
||||
numRead = fis.read(buffer);
|
||||
if (numRead > 0) {
|
||||
complete.update(buffer, 0, numRead);
|
||||
public static byte[] createChecksum(String filename) throws Exception {
|
||||
InputStream fis = null;
|
||||
MessageDigest complete;
|
||||
|
||||
try {
|
||||
fis = new FileInputStream(filename);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
complete = MessageDigest.getInstance("SHA1");
|
||||
|
||||
int numRead;
|
||||
do {
|
||||
numRead = fis.read(buffer);
|
||||
if (numRead > 0) {
|
||||
complete.update(buffer, 0, numRead);
|
||||
}
|
||||
} while (numRead != -1);
|
||||
|
||||
return complete.digest();
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
} while (numRead != -1);
|
||||
fis.close();
|
||||
return complete.digest();
|
||||
}
|
||||
}
|
||||
|
||||
// see this How-to for a faster way to convert
|
||||
|
|
@ -28,9 +40,9 @@ public class ChechsumHelper {
|
|||
public static String getSHA1Checksum(String filename) throws Exception {
|
||||
byte[] b = createChecksum(filename);
|
||||
String result = "";
|
||||
for (int i=0; i < b.length; i++) {
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
result +=
|
||||
Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
|
||||
Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue