Skip to content

Commit

Permalink
Merge "Make dumpHexString() tolerate null arrays."
Browse files Browse the repository at this point in the history
am: a917c1d

Change-Id: Ib0160e232cab0a713853a65eef26f7a02d65c1f1
  • Loading branch information
codewiz authored and android-build-merger committed Jun 15, 2018
2 parents 3eb2ad1 + a917c1d commit 7bb253d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/java/com/android/internal/util/HexDump.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@

package com.android.internal.util;

import android.annotation.Nullable;

public class HexDump
{
private final static char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
private final static char[] HEX_LOWER_CASE_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

public static String dumpHexString(byte[] array)
{
public static String dumpHexString(@Nullable byte[] array) {
if (array == null) return "(null)";
return dumpHexString(array, 0, array.length);
}

public static String dumpHexString(byte[] array, int offset, int length)
public static String dumpHexString(@Nullable byte[] array, int offset, int length)
{
if (array == null) return "(null)";
StringBuilder result = new StringBuilder();

byte[] line = new byte[16];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ public void testBytesToHexString() {
assertEquals("ABCDEF", HexDump.toHexString(
new byte[] { (byte) 0xab, (byte) 0xcd, (byte) 0xef }, true));
}
public void testNullArray() {
assertEquals("(null)", HexDump.toHexString(null));
}
}

0 comments on commit 7bb253d

Please sign in to comment.