-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add insertByteArray and better test verification
- Loading branch information
Frotty
committed
Jan 7, 2018
1 parent
ad0effc
commit b8589ef
Showing
5 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package systems.crigges.jmpq3; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.security.DigestInputStream; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
/** | ||
* Created by Frotty on 11.06.2017. | ||
*/ | ||
public class TestHelper { | ||
// stolen from http://stackoverflow.com/a/304350/303637 | ||
public static String md5(File f) { | ||
try { | ||
byte[] buf = new byte[1024]; | ||
MessageDigest md = MessageDigest.getInstance("MD5"); | ||
try (InputStream is = new FileInputStream(f); | ||
DigestInputStream dis = new DigestInputStream(is, md);) { | ||
while (dis.read(buf) >= 0); | ||
} | ||
byte[] digest = md.digest(); | ||
return bytesToHex(digest); | ||
} catch (NoSuchAlgorithmException | IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
// stolen from http://stackoverflow.com/a/9855338/303637 | ||
final protected static char[] hexArray = "0123456789abcdef".toCharArray(); | ||
public static String bytesToHex(byte[] bytes) { | ||
char[] hexChars = new char[bytes.length * 2]; | ||
int v; | ||
for ( int j = 0; j < bytes.length; j++ ) { | ||
v = bytes[j] & 0xFF; | ||
hexChars[j * 2] = hexArray[v >>> 4]; | ||
hexChars[j * 2 + 1] = hexArray[v & 0x0F]; | ||
} | ||
return new String(hexChars); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters