summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/util/Hash.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/util/Hash.java')
-rw-r--r--src/main/java/org/openslx/imagemaster/util/Hash.java26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/main/java/org/openslx/imagemaster/util/Hash.java b/src/main/java/org/openslx/imagemaster/util/Hash.java
index 24eb595..8db6a5f 100644
--- a/src/main/java/org/openslx/imagemaster/util/Hash.java
+++ b/src/main/java/org/openslx/imagemaster/util/Hash.java
@@ -10,6 +10,7 @@ public class Hash
* Cache of md5 digesters
*/
private static final ThreadLocal<MessageDigest> md5hash = new ThreadLocal<MessageDigest>() {
+
@Override
public MessageDigest initialValue()
{
@@ -17,7 +18,7 @@ public class Hash
return MessageDigest.getInstance( "MD5" );
} catch ( NoSuchAlgorithmException e ) {
e.printStackTrace();
- System.exit(1);
+ System.exit( 1 );
return null;
}
}
@@ -26,6 +27,7 @@ public class Hash
* Cache of sha256 digesters
*/
private static final ThreadLocal<MessageDigest> sha256hash = new ThreadLocal<MessageDigest>() {
+
@Override
public MessageDigest initialValue()
{
@@ -33,7 +35,7 @@ public class Hash
return MessageDigest.getInstance( "SHA-256" );
} catch ( NoSuchAlgorithmException e ) {
e.printStackTrace();
- System.exit(1);
+ System.exit( 1 );
return null;
}
}
@@ -48,7 +50,7 @@ public class Hash
private static final Charset UTF8 = Charset.forName( "UTF-8" );
// MD5
-
+
/**
* Compute md5 hash of given binary data.
*
@@ -59,7 +61,7 @@ public class Hash
{
return toHexString( md5hash.get().digest( bytes ) );
}
-
+
/**
* Compute md5 hash of the given string.
* The string will be converted to utf-8 before computation.
@@ -69,11 +71,11 @@ public class Hash
*/
public static String md5( final String text )
{
- return md5( text.getBytes( UTF8 ));
+ return md5( text.getBytes( UTF8 ) );
}
-
+
// SHA-256
-
+
/**
* Compute sha256 hash of given binary data.
*
@@ -94,20 +96,20 @@ public class Hash
*/
public static String sha256( final String text )
{
- return sha256( text.getBytes( UTF8 ));
+ return sha256( text.getBytes( UTF8 ) );
}
-
+
// Helper
-
+
/**
* Convert given binary data to hex.
*
* @param bytes binary data in a byte array
- * @return upper case hex representation of bytes
+ * @return upper case hex representation of bytes
*/
private static String toHexString( final byte[] bytes )
{
- final char[] hexChars = new char[bytes.length * 2];
+ final char[] hexChars = new char[ bytes.length * 2 ];
for ( int j = 0; j < bytes.length; ++j ) {
final int v = bytes[j] & 0xFF;
hexChars[j * 2] = HEX_CHARS[v >>> 4];