HexFormat.of().formatHex(byte[] arr)
- transform byte array to hex formated string,
For comparison array formated with Arrays.toString()
[-32,79,-48,32,-22,58,105,16,-94,-40,8,0,43,48,48,-99],
with formatHex() it is string "
e04fd020ea3a6910a2d808002b30309d".
The main difference is that array formatted with formatHex()
does not contain signed values, what was a condition
in the task description.
The test was required to be changed as well because it was
dependent on Arrays.toString() method.
JIRA: MDSAL-692
Change-Id: Ica9e399d61d54ac19369d3b2a9f60c9690b44128
Signed-off-by: ivan.martiniak <ivan.martiniak@pantheon.tech>
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.HexFormat;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test;
final List<Range<Integer>> lengthConstraints = new ArrayList<>();
lengthConstraints.add(Range.closed(1, 10));
byte[] arg = new byte[] {};
- String expectedMsg = String.format("Invalid length: %s, expected: %s.", Arrays.toString(arg),
+ String expectedMsg = String.format("Invalid length: %s, expected: %s.", HexFormat.of().formatHex(arg),
lengthConstraints);
CompilationTestUtils.assertContainsRestrictionCheck(builderObj, method, expectedMsg, arg);
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Arrays;
import java.util.Collection;
+import java.util.HexFormat;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
*/
public static void appendValue(final ToStringHelper helper, final String name, final byte[] value) {
if (value != null) {
- // FIXME: MDSAL-692: use hex-encoding instead
- helper.add(name, Arrays.toString(value));
+ helper.add(name, HexFormat.of().formatHex(value));
}
}
* @throws IllegalArgumentException always
*/
public static void throwInvalidLength(final String expected, final byte[] actual) {
- // FIXME: MDSAL-692: use hex-encoding instead
- throwInvalidLength(expected, Arrays.toString(actual));
+ throwInvalidLength(expected, HexFormat.of().formatHex(actual));
}
/**