Skip to content

Commit f8abb58

Browse files
committed
Wire: Make hex logging more concise
1 parent f0e7a7e commit f8abb58

2 files changed

Lines changed: 14 additions & 22 deletions

File tree

  • httpclient5/src

httpclient5/src/main/java/org/apache/hc/client5/http/impl/Wire.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.nio.ByteBuffer;
3131

32+
import org.apache.hc.client5.http.utils.Hex;
3233
import org.apache.hc.core5.annotation.Internal;
3334
import org.apache.hc.core5.util.Args;
3435
import org.slf4j.Logger;
@@ -93,7 +94,7 @@ private void wire(final String header, final byte[] b, final int pos, final int
9394
buffer.setLength(0);
9495
} else if (ch < 32 || ch >= 127) {
9596
buffer.append("[0x");
96-
buffer.append(Integer.toHexString(ch));
97+
buffer.append(Hex.encodeHexString(new byte[]{(byte) ch}));
9798
buffer.append("]");
9899
} else {
99100
buffer.append((char) ch);

httpclient5/src/test/java/org/apache/hc/client5/http/impl/WireTest.java

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,18 @@ void allBytes() {
4949

5050
wire.input(bs);
5151

52-
verify(log).debug("{} {}", "id", "<< \"[0x0][0x1][0x2][0x3][0x4][0x5][0x6][0x7][0x8][0x9][\\n]\"");
53-
verify(log).debug("{} {}", "id",
54-
"<< \"[0xb][0xc][\\r][0xe][0xf][0x10][0x11][0x12][0x13][0x14][0x15][0x16][0x17][0x18][0x19][0x1a][0x1b]"
55-
+ "[0x1c][0x1d][0x1e][0x1f] !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefg"
56-
+ "hijklmnopqrstuvwxyz{|}~[0x7f][0xffffff80][0xffffff81][0xffffff82][0xffffff83][0xffffff84]"
57-
+ "[0xffffff85][0xffffff86][0xffffff87][0xffffff88][0xffffff89][0xffffff8a][0xffffff8b][0xffffff8c]"
58-
+ "[0xffffff8d][0xffffff8e][0xffffff8f][0xffffff90][0xffffff91][0xffffff92][0xffffff93][0xffffff94]"
59-
+ "[0xffffff95][0xffffff96][0xffffff97][0xffffff98][0xffffff99][0xffffff9a][0xffffff9b][0xffffff9c]"
60-
+ "[0xffffff9d][0xffffff9e][0xffffff9f][0xffffffa0][0xffffffa1][0xffffffa2][0xffffffa3][0xffffffa4]"
61-
+ "[0xffffffa5][0xffffffa6][0xffffffa7][0xffffffa8][0xffffffa9][0xffffffaa][0xffffffab][0xffffffac]"
62-
+ "[0xffffffad][0xffffffae][0xffffffaf][0xffffffb0][0xffffffb1][0xffffffb2][0xffffffb3][0xffffffb4]"
63-
+ "[0xffffffb5][0xffffffb6][0xffffffb7][0xffffffb8][0xffffffb9][0xffffffba][0xffffffbb][0xffffffbc]"
64-
+ "[0xffffffbd][0xffffffbe][0xffffffbf][0xffffffc0][0xffffffc1][0xffffffc2][0xffffffc3][0xffffffc4]"
65-
+ "[0xffffffc5][0xffffffc6][0xffffffc7][0xffffffc8][0xffffffc9][0xffffffca][0xffffffcb][0xffffffcc]"
66-
+ "[0xffffffcd][0xffffffce][0xffffffcf][0xffffffd0][0xffffffd1][0xffffffd2][0xffffffd3][0xffffffd4]"
67-
+ "[0xffffffd5][0xffffffd6][0xffffffd7][0xffffffd8][0xffffffd9][0xffffffda][0xffffffdb][0xffffffdc]"
68-
+ "[0xffffffdd][0xffffffde][0xffffffdf][0xffffffe0][0xffffffe1][0xffffffe2][0xffffffe3][0xffffffe4]"
69-
+ "[0xffffffe5][0xffffffe6][0xffffffe7][0xffffffe8][0xffffffe9][0xffffffea][0xffffffeb][0xffffffec]"
70-
+ "[0xffffffed][0xffffffee][0xffffffef][0xfffffff0][0xfffffff1][0xfffffff2][0xfffffff3][0xfffffff4]"
71-
+ "[0xfffffff5][0xfffffff6][0xfffffff7][0xfffffff8][0xfffffff9][0xfffffffa][0xfffffffb][0xfffffffc]"
72-
+ "[0xfffffffd][0xfffffffe][0xffffffff]\"");
52+
verify(log).debug("{} {}", "id", "<< \"[0x00][0x01][0x02][0x03][0x04][0x05][0x06][0x07][0x08][0x09][\\n]\"");
53+
verify(log).debug("{} {}", "id", "<< \"[0x0b][0x0c][\\r][0x0e][0x0f][0x10][0x11][0x12][0x13][0x14][0x15][0x16]"
54+
+ "[0x17][0x18][0x19][0x1a][0x1b][0x1c][0x1d][0x1e][0x1f] !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO"
55+
+ "PQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~[0x7f][0x80][0x81][0x82][0x83][0x84][0x85][0x86][0x87]"
56+
+ "[0x88][0x89][0x8a][0x8b][0x8c][0x8d][0x8e][0x8f][0x90][0x91][0x92][0x93][0x94][0x95][0x96][0x97][0x98]"
57+
+ "[0x99][0x9a][0x9b][0x9c][0x9d][0x9e][0x9f][0xa0][0xa1][0xa2][0xa3][0xa4][0xa5][0xa6][0xa7][0xa8][0xa9]"
58+
+ "[0xaa][0xab][0xac][0xad][0xae][0xaf][0xb0][0xb1][0xb2][0xb3][0xb4][0xb5][0xb6][0xb7][0xb8][0xb9][0xba]"
59+
+ "[0xbb][0xbc][0xbd][0xbe][0xbf][0xc0][0xc1][0xc2][0xc3][0xc4][0xc5][0xc6][0xc7][0xc8][0xc9][0xca][0xcb]"
60+
+ "[0xcc][0xcd][0xce][0xcf][0xd0][0xd1][0xd2][0xd3][0xd4][0xd5][0xd6][0xd7][0xd8][0xd9][0xda][0xdb][0xdc]"
61+
+ "[0xdd][0xde][0xdf][0xe0][0xe1][0xe2][0xe3][0xe4][0xe5][0xe6][0xe7][0xe8][0xe9][0xea][0xeb][0xec][0xed]"
62+
+ "[0xee][0xef][0xf0][0xf1][0xf2][0xf3][0xf4][0xf5][0xf6][0xf7][0xf8][0xf9][0xfa][0xfb][0xfc][0xfd][0xfe]"
63+
+ "[0xff]\"");
7364
verifyNoMoreInteractions(log);
7465
}
7566
}

0 commit comments

Comments
 (0)