Skip to content

Commit 86d1045

Browse files
committed
Internal refactoring
1 parent 873ecaa commit 86d1045

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

  • src/main/java/org/apache/commons/codec/binary

src/main/java/org/apache/commons/codec/binary/Hex.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public static char[] encodeHex(final byte[] data) {
145145
* @since 1.4
146146
*/
147147
public static char[] encodeHex(final byte[] data, final boolean toLowerCase) {
148-
return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
148+
return encodeHex(data, toAlphabet(toLowerCase));
149149
}
150150

151151
/**
@@ -176,7 +176,7 @@ protected static char[] encodeHex(final byte[] data, final char[] toDigits) {
176176
* @since 1.15
177177
*/
178178
public static char[] encodeHex(final byte[] data, final int dataOffset, final int dataLen, final boolean toLowerCase) {
179-
return encodeHex(data, dataOffset, dataLen, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER, new char[dataLen << 1], 0);
179+
return encodeHex(data, dataOffset, dataLen, toAlphabet(toLowerCase), new char[dataLen << 1], 0);
180180
}
181181

182182
/**
@@ -191,7 +191,7 @@ public static char[] encodeHex(final byte[] data, final int dataOffset, final in
191191
* @since 1.15
192192
*/
193193
public static void encodeHex(final byte[] data, final int dataOffset, final int dataLen, final boolean toLowerCase, final char[] out, final int outOffset) {
194-
encodeHex(data, dataOffset, dataLen, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER, out, outOffset);
194+
encodeHex(data, dataOffset, dataLen, toAlphabet(toLowerCase), out, outOffset);
195195
}
196196

197197
/**
@@ -244,7 +244,7 @@ public static char[] encodeHex(final ByteBuffer data) {
244244
* @since 1.11
245245
*/
246246
public static char[] encodeHex(final ByteBuffer data, final boolean toLowerCase) {
247-
return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
247+
return encodeHex(data, toAlphabet(toLowerCase));
248248
}
249249

250250
/**
@@ -321,6 +321,16 @@ public static String encodeHexString(final ByteBuffer data, final boolean toLowe
321321
return new String(encodeHex(data, toLowerCase));
322322
}
323323

324+
/**
325+
* Converts a boolean to an alphabet.
326+
*
327+
* @param toLowerCase true for lowercase, false for uppercase.
328+
* @return an alphabet.
329+
*/
330+
private static char[] toAlphabet(final boolean toLowerCase) {
331+
return toLowerCase ? DIGITS_LOWER : DIGITS_UPPER;
332+
}
333+
324334
/**
325335
* Convert the byte buffer to a byte array. All bytes identified by
326336
* {@link ByteBuffer#remaining()} will be used.

0 commit comments

Comments
 (0)