mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8251989: Hex formatting and parsing utility
Reviewed-by: tvaleev, chegar, naoto, darcy
This commit is contained in:
parent
efd61c6f53
commit
aa9c136d67
14 changed files with 1921 additions and 167 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -26,6 +26,7 @@
|
|||
package javax.net.ssl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HexFormat;
|
||||
|
||||
/**
|
||||
* Instances of this class represent a server name in a Server Name
|
||||
|
@ -52,9 +53,6 @@ public abstract class SNIServerName {
|
|||
// the encoded value of the server name
|
||||
private final byte[] encoded;
|
||||
|
||||
// the hex digitals
|
||||
private static final char[] HEXES = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
/**
|
||||
* Creates an {@code SNIServerName} using the specified name type and
|
||||
* encoded value.
|
||||
|
@ -192,22 +190,7 @@ public abstract class SNIServerName {
|
|||
if (bytes.length == 0) {
|
||||
return "(empty)";
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder(bytes.length * 3 - 1);
|
||||
boolean isInitial = true;
|
||||
for (byte b : bytes) {
|
||||
if (isInitial) {
|
||||
isInitial = false;
|
||||
} else {
|
||||
sb.append(':');
|
||||
}
|
||||
|
||||
int k = b & 0xFF;
|
||||
sb.append(HEXES[k >>> 4]);
|
||||
sb.append(HEXES[k & 0xF]);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
return HexFormat.ofDelimiter(":").withUpperCase().formatHex(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue