Use java.util.HexFormat where appropriate

See gh-31477
This commit is contained in:
dreis2211
2022-06-21 08:30:19 +02:00
committed by Andy Wilkinson
parent 76cd2466ac
commit cc91009b70
3 changed files with 11 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,10 @@
package org.springframework.boot.buildpack.platform.docker.type;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HexFormat;
import java.util.function.Function;
import org.springframework.util.Assert;
@@ -126,9 +126,7 @@ public final class VolumeName {
private static String asHexString(byte[] digest, int digestLength) {
Assert.isTrue(digestLength <= digest.length,
() -> "DigestLength must be less than or equal to " + digest.length);
byte[] shortDigest = new byte[6];
System.arraycopy(digest, 0, shortDigest, 0, shortDigest.length);
return String.format("%0" + digestLength + "x", new BigInteger(1, shortDigest));
return HexFormat.of().formatHex(digest, 0, digestLength);
}
/**