Polish "Use java.util.HexFormat where appropriate"

See gh-31477
pull/31494/head
Andy Wilkinson 2 years ago
parent cc91009b70
commit 965fbf4494

@ -27,6 +27,7 @@ import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.security.MessageDigest;
import java.util.EnumSet;
import java.util.HexFormat;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@ -41,8 +42,6 @@ import org.springframework.util.StringUtils;
*/
public class ApplicationTemp {
private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
private static final FileAttribute<?>[] NO_FILE_ATTRIBUTES = {};
private static final EnumSet<PosixFilePermission> DIRECTORY_PERMISSIONS = EnumSet.of(PosixFilePermission.OWNER_READ,
@ -92,7 +91,7 @@ public class ApplicationTemp {
private Path getPath() {
if (this.path == null) {
synchronized (this) {
String hash = toHexString(generateHash(this.sourceClass));
String hash = HexFormat.of().withUpperCase().formatHex(generateHash(this.sourceClass));
this.path = createDirectory(getTempDirectory().resolve(hash));
}
}
@ -160,14 +159,4 @@ public class ApplicationTemp {
return source.toString().getBytes();
}
private String toHexString(byte[] bytes) {
char[] hex = new char[bytes.length * 2];
for (int i = 0; i < bytes.length; i++) {
int b = bytes[i] & 0xFF;
hex[i * 2] = HEX_CHARS[b >>> 4];
hex[i * 2 + 1] = HEX_CHARS[b & 0x0F];
}
return new String(hex);
}
}

Loading…
Cancel
Save