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-2019 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.
@@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.util.HexFormat;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -45,7 +46,7 @@ public class HttpTunnelPayload {
private static final int BUFFER_SIZE = 1024 * 100;
protected static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
private static final HexFormat HEX_FORMAT = HexFormat.of().withUpperCase();
private static final Log logger = LogFactory.getLog(HttpTunnelPayload.class);
@@ -173,13 +174,7 @@ public class HttpTunnelPayload {
*/
public String toHexString() {
byte[] bytes = this.data.array();
char[] hex = new char[this.data.remaining() * 2];
for (int i = this.data.position(); i < this.data.remaining(); i++) {
int b = bytes[i] & 0xFF;
hex[i * 2] = HEX_CHARS[b >>> 4];
hex[i * 2 + 1] = HEX_CHARS[b & 0x0F];
}
return new String(hex);
return HEX_FORMAT.formatHex(bytes);
}
}