8259493: [test] Use HexFormat instead of adhoc hex utilities in network code and locale SoftKeys
Reviewed-by: lancea, naoto
This commit is contained in:
parent
090bd3afc3
commit
876c7fb5f7
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -186,11 +186,6 @@ public class B6870935 {
|
|||||||
return finalHash;
|
return finalHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static char charArray[] = {
|
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
|
||||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
|
|
||||||
};
|
|
||||||
|
|
||||||
private String encode(String src, char[] passwd, MessageDigest md) {
|
private String encode(String src, char[] passwd, MessageDigest md) {
|
||||||
md.update(src.getBytes());
|
md.update(src.getBytes());
|
||||||
if (passwd != null) {
|
if (passwd != null) {
|
||||||
@ -201,15 +196,7 @@ public class B6870935 {
|
|||||||
Arrays.fill(passwdBytes, (byte)0x00);
|
Arrays.fill(passwdBytes, (byte)0x00);
|
||||||
}
|
}
|
||||||
byte[] digest = md.digest();
|
byte[] digest = md.digest();
|
||||||
|
return HexFormat.of().formatHex(digest);
|
||||||
StringBuffer res = new StringBuffer(digest.length * 2);
|
|
||||||
for (int i = 0; i < digest.length; i++) {
|
|
||||||
int hashchar = ((digest[i] >>> 4) & 0xf);
|
|
||||||
res.append(charArray[hashchar]);
|
|
||||||
hashchar = (digest[i] & 0xf);
|
|
||||||
res.append(charArray[hashchar]);
|
|
||||||
}
|
|
||||||
return res.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -52,6 +52,7 @@ import java.time.Instant;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import java.util.HexFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -582,11 +583,6 @@ public class HTTPTestServer extends HTTPTest {
|
|||||||
|
|
||||||
// Code stolen from DigestAuthentication:
|
// Code stolen from DigestAuthentication:
|
||||||
|
|
||||||
private static final char charArray[] = {
|
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
|
||||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
|
|
||||||
};
|
|
||||||
|
|
||||||
private static String encode(String src, char[] passwd, MessageDigest md) {
|
private static String encode(String src, char[] passwd, MessageDigest md) {
|
||||||
try {
|
try {
|
||||||
md.update(src.getBytes("ISO-8859-1"));
|
md.update(src.getBytes("ISO-8859-1"));
|
||||||
@ -601,15 +597,7 @@ public class HTTPTestServer extends HTTPTest {
|
|||||||
Arrays.fill(passwdBytes, (byte)0x00);
|
Arrays.fill(passwdBytes, (byte)0x00);
|
||||||
}
|
}
|
||||||
byte[] digest = md.digest();
|
byte[] digest = md.digest();
|
||||||
|
return HexFormat.of().formatHex(digest);
|
||||||
StringBuilder res = new StringBuilder(digest.length * 2);
|
|
||||||
for (int i = 0; i < digest.length; i++) {
|
|
||||||
int hashchar = ((digest[i] >>> 4) & 0xf);
|
|
||||||
res.append(charArray[hashchar]);
|
|
||||||
hashchar = (digest[i] & 0xf);
|
|
||||||
res.append(charArray[hashchar]);
|
|
||||||
}
|
|
||||||
return res.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String computeDigest(boolean isRequest,
|
public static String computeDigest(boolean isRequest,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -54,6 +54,7 @@ import java.time.Instant;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import java.util.HexFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -821,11 +822,6 @@ public abstract class DigestEchoServer implements HttpServerAdapters {
|
|||||||
|
|
||||||
// Code stolen from DigestAuthentication:
|
// Code stolen from DigestAuthentication:
|
||||||
|
|
||||||
private static final char charArray[] = {
|
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
|
||||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
|
|
||||||
};
|
|
||||||
|
|
||||||
private static String encode(String src, char[] passwd, MessageDigest md) {
|
private static String encode(String src, char[] passwd, MessageDigest md) {
|
||||||
try {
|
try {
|
||||||
md.update(src.getBytes("ISO-8859-1"));
|
md.update(src.getBytes("ISO-8859-1"));
|
||||||
@ -840,15 +836,7 @@ public abstract class DigestEchoServer implements HttpServerAdapters {
|
|||||||
Arrays.fill(passwdBytes, (byte)0x00);
|
Arrays.fill(passwdBytes, (byte)0x00);
|
||||||
}
|
}
|
||||||
byte[] digest = md.digest();
|
byte[] digest = md.digest();
|
||||||
|
return HexFormat.of().formatHex(digest);
|
||||||
StringBuilder res = new StringBuilder(digest.length * 2);
|
|
||||||
for (int i = 0; i < digest.length; i++) {
|
|
||||||
int hashchar = ((digest[i] >>> 4) & 0xf);
|
|
||||||
res.append(charArray[hashchar]);
|
|
||||||
hashchar = (digest[i] & 0xf);
|
|
||||||
res.append(charArray[hashchar]);
|
|
||||||
}
|
|
||||||
return res.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String computeDigest(boolean isRequest,
|
public static String computeDigest(boolean isRequest,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -33,8 +33,6 @@ import java.util.*;
|
|||||||
|
|
||||||
public class SoftKeys {
|
public class SoftKeys {
|
||||||
|
|
||||||
private static final char[] CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
// With 4 characters in "language", we'll fill up a 16M heap quickly,
|
// With 4 characters in "language", we'll fill up a 16M heap quickly,
|
||||||
@ -44,7 +42,7 @@ public class SoftKeys {
|
|||||||
// been cleared.
|
// been cleared.
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
for (int j = 0; j < 512*1024; j++) {
|
for (int j = 0; j < 512*1024; j++) {
|
||||||
new Locale(langForInt(j), "", "");
|
new Locale(HexFormat.of().toHexDigits((short)j), "", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
@ -57,14 +55,5 @@ public class SoftKeys {
|
|||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String langForInt(int val) {
|
|
||||||
StringBuilder buf = new StringBuilder(4);
|
|
||||||
buf.append(CHARS[(val >> 12) & 0xF]);
|
|
||||||
buf.append(CHARS[(val >> 8) & 0xF]);
|
|
||||||
buf.append(CHARS[(val >> 4) & 0xF]);
|
|
||||||
buf.append(CHARS[(val >> 0) & 0xF]);
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -172,11 +172,6 @@ class DigestServer extends Thread {
|
|||||||
return finalHash;
|
return finalHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static char charArray[] = {
|
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
|
||||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
|
|
||||||
};
|
|
||||||
|
|
||||||
private String encode(String src, char[] passwd, MessageDigest md) {
|
private String encode(String src, char[] passwd, MessageDigest md) {
|
||||||
md.update(src.getBytes());
|
md.update(src.getBytes());
|
||||||
if (passwd != null) {
|
if (passwd != null) {
|
||||||
@ -187,15 +182,7 @@ class DigestServer extends Thread {
|
|||||||
Arrays.fill(passwdBytes, (byte)0x00);
|
Arrays.fill(passwdBytes, (byte)0x00);
|
||||||
}
|
}
|
||||||
byte[] digest = md.digest();
|
byte[] digest = md.digest();
|
||||||
|
return HexFormat.of().formatHex(digest);
|
||||||
StringBuffer res = new StringBuffer(digest.length * 2);
|
|
||||||
for (int i = 0; i < digest.length; i++) {
|
|
||||||
int hashchar = ((digest[i] >>> 4) & 0xf);
|
|
||||||
res.append(charArray[hashchar]);
|
|
||||||
hashchar = (digest[i] & 0xf);
|
|
||||||
res.append(charArray[hashchar]);
|
|
||||||
}
|
|
||||||
return res.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user