mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-18 18:14:38 +02:00
8263754: HexFormat 'fromHex' methods should be static
Reviewed-by: redestad, naoto, chegar
This commit is contained in:
parent
a5d7de2351
commit
8cf1c62c34
5 changed files with 39 additions and 54 deletions
|
@ -877,7 +877,7 @@ public final class HexFormat {
|
|||
* @return {@code true} if the character is valid a hexadecimal character,
|
||||
* otherwise {@code false}
|
||||
*/
|
||||
public boolean isHexDigit(int ch) {
|
||||
public static boolean isHexDigit(int ch) {
|
||||
return ((ch >>> 8) == 0 && DIGITS[ch] >= 0);
|
||||
}
|
||||
|
||||
|
@ -889,13 +889,12 @@ public final class HexFormat {
|
|||
* <li>{@code (ch - 'A' + 10)} for {@code 'A'} through {@code 'F'} inclusive, and
|
||||
* <li>{@code (ch - 'a' + 10)} for {@code 'a'} through {@code 'f'} inclusive.
|
||||
* </ul>
|
||||
* The delimiter, prefix, suffix, and uppercase parameters are not used.
|
||||
*
|
||||
* @param ch a character or codepoint
|
||||
* @return the value {@code 0-15}
|
||||
* @throws NumberFormatException if the codepoint is not a hexadecimal character
|
||||
*/
|
||||
public int fromHexDigit(int ch) {
|
||||
public static int fromHexDigit(int ch) {
|
||||
int value;
|
||||
if ((ch >>> 8) == 0 && (value = DIGITS[ch]) >= 0) {
|
||||
return value;
|
||||
|
@ -907,7 +906,6 @@ public final class HexFormat {
|
|||
* Returns a value parsed from two hexadecimal characters in a string.
|
||||
* The characters in the range from {@code index} to {@code index + 1},
|
||||
* inclusive, must be valid hex digits according to {@link #fromHexDigit(int)}.
|
||||
* The delimiter, prefix, suffix, and uppercase parameters are not used.
|
||||
*
|
||||
* @param string a CharSequence containing the characters
|
||||
* @param index the index of the first character of the range
|
||||
|
@ -917,7 +915,7 @@ public final class HexFormat {
|
|||
* @throws IndexOutOfBoundsException if the range is out of bounds
|
||||
* for the {@code CharSequence}
|
||||
*/
|
||||
private int fromHexDigits(CharSequence string, int index) {
|
||||
private static int fromHexDigits(CharSequence string, int index) {
|
||||
Objects.requireNonNull(string, "string");
|
||||
int high = fromHexDigit(string.charAt(index));
|
||||
int low = fromHexDigit(string.charAt(index + 1));
|
||||
|
@ -929,7 +927,6 @@ public final class HexFormat {
|
|||
* The hexadecimal characters are parsed from most significant to least significant
|
||||
* using {@link #fromHexDigit(int)} to form an unsigned value.
|
||||
* The value is zero extended to 32 bits and is returned as an {@code int}.
|
||||
* The delimiter, prefix, suffix, and uppercase parameters are not used.
|
||||
*
|
||||
* @apiNote
|
||||
* {@link Integer#parseInt(String, int) Integer.parseInt(s, 16)} and
|
||||
|
@ -944,7 +941,7 @@ public final class HexFormat {
|
|||
* @throws IllegalArgumentException if the string length is greater than eight (8) or
|
||||
* if any of the characters is not a hexadecimal character
|
||||
*/
|
||||
public int fromHexDigits(CharSequence string) {
|
||||
public static int fromHexDigits(CharSequence string) {
|
||||
Objects.requireNonNull(string, "string");
|
||||
int length = checkDigitCount(0, string.length(), 8);
|
||||
int value = 0;
|
||||
|
@ -961,7 +958,6 @@ public final class HexFormat {
|
|||
* are parsed from most significant to least significant
|
||||
* using {@link #fromHexDigit(int)} to form an unsigned value.
|
||||
* The value is zero extended to 32 bits and is returned as an {@code int}.
|
||||
* The delimiter, prefix, suffix, and uppercase parameters are not used.
|
||||
*
|
||||
* @apiNote
|
||||
* {@link Integer#parseInt(String, int) Integer.parseInt(s, 16)} and
|
||||
|
@ -980,7 +976,7 @@ public final class HexFormat {
|
|||
* @throws IllegalArgumentException if length of the range is greater than eight (8) or
|
||||
* if any of the characters is not a hexadecimal character
|
||||
*/
|
||||
public int fromHexDigits(CharSequence string, int fromIndex, int toIndex) {
|
||||
public static int fromHexDigits(CharSequence string, int fromIndex, int toIndex) {
|
||||
Objects.requireNonNull(string, "string");
|
||||
Objects.checkFromToIndex(fromIndex, toIndex, string.length());
|
||||
int length = checkDigitCount(fromIndex, toIndex, 8);
|
||||
|
@ -996,7 +992,6 @@ public final class HexFormat {
|
|||
* The hexadecimal characters are parsed from most significant to least significant
|
||||
* using {@link #fromHexDigit(int)} to form an unsigned value.
|
||||
* The value is zero extended to 64 bits and is returned as a {@code long}.
|
||||
* The delimiter, prefix, suffix, and uppercase parameters are not used.
|
||||
*
|
||||
* @apiNote
|
||||
* {@link Long#parseLong(String, int) Long.parseLong(s, 16)} and
|
||||
|
@ -1011,7 +1006,7 @@ public final class HexFormat {
|
|||
* @throws IllegalArgumentException if the string length is greater than sixteen (16) or
|
||||
* if any of the characters is not a hexadecimal character
|
||||
*/
|
||||
public long fromHexDigitsToLong(CharSequence string) {
|
||||
public static long fromHexDigitsToLong(CharSequence string) {
|
||||
Objects.requireNonNull(string, "string");
|
||||
int length = checkDigitCount(0, string.length(), 16);
|
||||
long value = 0L;
|
||||
|
@ -1028,7 +1023,6 @@ public final class HexFormat {
|
|||
* are parsed from most significant to least significant
|
||||
* using {@link #fromHexDigit(int)} to form an unsigned value.
|
||||
* The value is zero extended to 64 bits and is returned as a {@code long}.
|
||||
* The delimiter, prefix, suffix, and uppercase parameters are not used.
|
||||
*
|
||||
* @apiNote
|
||||
* {@link Long#parseLong(String, int) Long.parseLong(s, 16)} and
|
||||
|
@ -1047,7 +1041,7 @@ public final class HexFormat {
|
|||
* @throws IllegalArgumentException if the length of the range is greater than sixteen (16) or
|
||||
* if any of the characters is not a hexadecimal character
|
||||
*/
|
||||
public long fromHexDigitsToLong(CharSequence string, int fromIndex, int toIndex) {
|
||||
public static long fromHexDigitsToLong(CharSequence string, int fromIndex, int toIndex) {
|
||||
Objects.requireNonNull(string, "string");
|
||||
Objects.checkFromToIndex(fromIndex, toIndex, string.length());
|
||||
int length = checkDigitCount(fromIndex, toIndex, 16);
|
||||
|
|
|
@ -815,11 +815,10 @@ class RevocationChecker extends PKIXRevocationChecker {
|
|||
* Removes any non-hexadecimal characters from a string.
|
||||
*/
|
||||
private static String stripOutSeparators(String value) {
|
||||
HexFormat hex = HexFormat.of();
|
||||
char[] chars = value.toCharArray();
|
||||
StringBuilder hexNumber = new StringBuilder();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
if (hex.isHexDigit(chars[i])) {
|
||||
if (HexFormat.isHexDigit(chars[i])) {
|
||||
hexNumber.append(chars[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ import java.security.cert.URICertStoreParameters;
|
|||
|
||||
import java.security.interfaces.ECKey;
|
||||
import java.security.interfaces.EdECKey;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.security.spec.ECParameterSpec;
|
||||
import java.text.Collator;
|
||||
import java.text.MessageFormat;
|
||||
|
@ -4574,16 +4573,15 @@ public final class Main {
|
|||
break;
|
||||
case -1:
|
||||
ObjectIdentifier oid = ObjectIdentifier.of(name);
|
||||
HexFormat hexFmt = HexFormat.of();
|
||||
byte[] data = null;
|
||||
if (value != null) {
|
||||
data = new byte[value.length() / 2 + 1];
|
||||
int pos = 0;
|
||||
for (char c: value.toCharArray()) {
|
||||
if (!hexFmt.isHexDigit(c)) {
|
||||
if (!HexFormat.isHexDigit(c)) {
|
||||
continue;
|
||||
}
|
||||
int hex = hexFmt.fromHexDigit(c);
|
||||
int hex = HexFormat.fromHexDigit(c);
|
||||
if (pos % 2 == 0) {
|
||||
data[pos/2] = (byte)(hex << 4);
|
||||
} else {
|
||||
|
|
|
@ -29,7 +29,6 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.security.AccessController;
|
||||
import java.text.Normalizer;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -251,7 +250,6 @@ public class AVA implements DerEncoder {
|
|||
|
||||
private static DerValue parseHexString
|
||||
(Reader in, int format) throws IOException {
|
||||
HexFormat hex = HexFormat.of();
|
||||
int c;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte b = 0;
|
||||
|
@ -263,7 +261,7 @@ public class AVA implements DerEncoder {
|
|||
break;
|
||||
}
|
||||
try {
|
||||
int cVal = hex.fromHexDigit(c); // throws on invalid character
|
||||
int cVal = HexFormat.fromHexDigit(c); // throws on invalid character
|
||||
if ((cNdx % 2) == 1) {
|
||||
b = (byte)((b * 16) + (byte)(cVal));
|
||||
baos.write(b);
|
||||
|
@ -502,14 +500,13 @@ public class AVA implements DerEncoder {
|
|||
private static Byte getEmbeddedHexPair(int c1, Reader in)
|
||||
throws IOException {
|
||||
|
||||
HexFormat hex = HexFormat.of();
|
||||
if (hex.isHexDigit(c1)) {
|
||||
if (HexFormat.isHexDigit(c1)) {
|
||||
int c2 = readChar(in, "unexpected EOF - " +
|
||||
"escaped hex value must include two valid digits");
|
||||
|
||||
if (hex.isHexDigit(c2)) {
|
||||
int hi = hex.fromHexDigit(c1);
|
||||
int lo = hex.fromHexDigit(c2);
|
||||
if (HexFormat.isHexDigit(c2)) {
|
||||
int hi = HexFormat.fromHexDigit(c1);
|
||||
int lo = HexFormat.fromHexDigit(c2);
|
||||
return (byte)((hi<<4) + lo);
|
||||
} else {
|
||||
throw new IOException
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue