Skip to content

Commit cb4b3f5

Browse files
author
duke
committedJan 8, 2021
Automatic merge of jdk:master into master
2 parents e60873e + 876c7fb commit cb4b3f5

File tree

5 files changed

+12
-73
lines changed

5 files changed

+12
-73
lines changed
 

‎test/jdk/java/net/Authenticator/B6870935.java

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -186,11 +186,6 @@ private String computeDigest(
186186
return finalHash;
187187
}
188188

189-
private final static char charArray[] = {
190-
'0', '1', '2', '3', '4', '5', '6', '7',
191-
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
192-
};
193-
194189
private String encode(String src, char[] passwd, MessageDigest md) {
195190
md.update(src.getBytes());
196191
if (passwd != null) {
@@ -201,15 +196,7 @@ private String encode(String src, char[] passwd, MessageDigest md) {
201196
Arrays.fill(passwdBytes, (byte)0x00);
202197
}
203198
byte[] digest = md.digest();
204-
205-
StringBuffer res = new StringBuffer(digest.length * 2);
206-
for (int i = 0; i < digest.length; i++) {
207-
int hashchar = ((digest[i] >>> 4) & 0xf);
208-
res.append(charArray[hashchar]);
209-
hashchar = (digest[i] & 0xf);
210-
res.append(charArray[hashchar]);
211-
}
212-
return res.toString();
199+
return HexFormat.of().formatHex(digest);
213200
}
214201
}
215202

‎test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTestServer.java

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -52,6 +52,7 @@
5252
import java.util.ArrayList;
5353
import java.util.Arrays;
5454
import java.util.Base64;
55+
import java.util.HexFormat;
5556
import java.util.List;
5657
import java.util.Objects;
5758
import java.util.Random;
@@ -582,11 +583,6 @@ String getQoP(String defval) {
582583

583584
// Code stolen from DigestAuthentication:
584585

585-
private static final char charArray[] = {
586-
'0', '1', '2', '3', '4', '5', '6', '7',
587-
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
588-
};
589-
590586
private static String encode(String src, char[] passwd, MessageDigest md) {
591587
try {
592588
md.update(src.getBytes("ISO-8859-1"));
@@ -601,15 +597,7 @@ private static String encode(String src, char[] passwd, MessageDigest md) {
601597
Arrays.fill(passwdBytes, (byte)0x00);
602598
}
603599
byte[] digest = md.digest();
604-
605-
StringBuilder res = new StringBuilder(digest.length * 2);
606-
for (int i = 0; i < digest.length; i++) {
607-
int hashchar = ((digest[i] >>> 4) & 0xf);
608-
res.append(charArray[hashchar]);
609-
hashchar = (digest[i] & 0xf);
610-
res.append(charArray[hashchar]);
611-
}
612-
return res.toString();
600+
return HexFormat.of().formatHex(digest);
613601
}
614602

615603
public static String computeDigest(boolean isRequest,

‎test/jdk/java/net/httpclient/DigestEchoServer.java

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -54,6 +54,7 @@
5454
import java.util.ArrayList;
5555
import java.util.Arrays;
5656
import java.util.Base64;
57+
import java.util.HexFormat;
5758
import java.util.List;
5859
import java.util.Locale;
5960
import java.util.Objects;
@@ -821,11 +822,6 @@ String getQoP(String defval) {
821822

822823
// Code stolen from DigestAuthentication:
823824

824-
private static final char charArray[] = {
825-
'0', '1', '2', '3', '4', '5', '6', '7',
826-
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
827-
};
828-
829825
private static String encode(String src, char[] passwd, MessageDigest md) {
830826
try {
831827
md.update(src.getBytes("ISO-8859-1"));
@@ -840,15 +836,7 @@ private static String encode(String src, char[] passwd, MessageDigest md) {
840836
Arrays.fill(passwdBytes, (byte)0x00);
841837
}
842838
byte[] digest = md.digest();
843-
844-
StringBuilder res = new StringBuilder(digest.length * 2);
845-
for (int i = 0; i < digest.length; i++) {
846-
int hashchar = ((digest[i] >>> 4) & 0xf);
847-
res.append(charArray[hashchar]);
848-
hashchar = (digest[i] & 0xf);
849-
res.append(charArray[hashchar]);
850-
}
851-
return res.toString();
839+
return HexFormat.of().formatHex(digest);
852840
}
853841

854842
public static String computeDigest(boolean isRequest,

‎test/jdk/java/util/Locale/SoftKeys.java

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,8 +33,6 @@
3333

3434
public class SoftKeys {
3535

36-
private static final char[] CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
37-
3836
public static void main(String[] args) {
3937
try {
4038
// With 4 characters in "language", we'll fill up a 16M heap quickly,
@@ -44,7 +42,7 @@ public static void main(String[] args) {
4442
// been cleared.
4543
for (int i = 0; i < 2; i++) {
4644
for (int j = 0; j < 512*1024; j++) {
47-
new Locale(langForInt(j), "", "");
45+
new Locale(HexFormat.of().toHexDigits((short)j), "", "");
4846
}
4947
}
5048
} catch (OutOfMemoryError e) {
@@ -57,14 +55,5 @@ public static void main(String[] args) {
5755
System.gc();
5856
}
5957
}
60-
61-
private static String langForInt(int val) {
62-
StringBuilder buf = new StringBuilder(4);
63-
buf.append(CHARS[(val >> 12) & 0xF]);
64-
buf.append(CHARS[(val >> 8) & 0xF]);
65-
buf.append(CHARS[(val >> 4) & 0xF]);
66-
buf.append(CHARS[(val >> 0) & 0xF]);
67-
return buf.toString();
68-
}
6958
}
7059

‎test/jdk/sun/net/www/protocol/http/DigestTest.java

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -172,11 +172,6 @@ private String computeDigest(
172172
return finalHash;
173173
}
174174

175-
private final static char charArray[] = {
176-
'0', '1', '2', '3', '4', '5', '6', '7',
177-
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
178-
};
179-
180175
private String encode(String src, char[] passwd, MessageDigest md) {
181176
md.update(src.getBytes());
182177
if (passwd != null) {
@@ -187,15 +182,7 @@ private String encode(String src, char[] passwd, MessageDigest md) {
187182
Arrays.fill(passwdBytes, (byte)0x00);
188183
}
189184
byte[] digest = md.digest();
190-
191-
StringBuffer res = new StringBuffer(digest.length * 2);
192-
for (int i = 0; i < digest.length; i++) {
193-
int hashchar = ((digest[i] >>> 4) & 0xf);
194-
res.append(charArray[hashchar]);
195-
hashchar = (digest[i] & 0xf);
196-
res.append(charArray[hashchar]);
197-
}
198-
return res.toString();
185+
return HexFormat.of().formatHex(digest);
199186
}
200187

201188
}

0 commit comments

Comments
 (0)
Please sign in to comment.