Skip to content

Commit 03918b2

Browse files
committed
Refactor DefaultJobKeyGenerator to use org.springframework.util.DigestUtils
1 parent 36b1d0a commit 03918b2

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/DefaultJobKeyGenerator.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2018 the original author or authors.
2+
* Copyright 2006-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,15 +16,13 @@
1616
package org.springframework.batch.core;
1717

1818
import java.io.UnsupportedEncodingException;
19-
import java.math.BigInteger;
20-
import java.security.MessageDigest;
21-
import java.security.NoSuchAlgorithmException;
2219
import java.util.ArrayList;
2320
import java.util.Collections;
2421
import java.util.List;
2522
import java.util.Map;
2623

2724
import org.springframework.util.Assert;
25+
import org.springframework.util.DigestUtils;
2826

2927
/**
3028
* Default implementation of the {@link JobKeyGenerator} interface.
@@ -57,19 +55,8 @@ public String generateKey(JobParameters source) {
5755
stringBuffer.append(key).append("=").append(value).append(";");
5856
}
5957
}
60-
61-
MessageDigest digest;
62-
try {
63-
digest = MessageDigest.getInstance("MD5");
64-
} catch (NoSuchAlgorithmException e) {
65-
throw new IllegalStateException(
66-
"MD5 algorithm not available. Fatal (should be in the JDK).");
67-
}
68-
6958
try {
70-
byte[] bytes = digest.digest(stringBuffer.toString().getBytes(
71-
"UTF-8"));
72-
return String.format("%032x", new BigInteger(1, bytes));
59+
return DigestUtils.md5DigestAsHex(stringBuffer.toString().getBytes("UTF-8"));
7360
} catch (UnsupportedEncodingException e) {
7461
throw new IllegalStateException(
7562
"UTF-8 encoding not available. Fatal (should be in the JDK).");

0 commit comments

Comments
 (0)