From 01cdf806ede3ba7e2c85de4429c835b43d578003 Mon Sep 17 00:00:00 2001 From: Rainer Klute Date: Sat, 23 Aug 2003 14:49:35 +0000 Subject: [PATCH] Added a method for a formatted hex dump. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353306 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/util/HexDump.java | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/java/org/apache/poi/util/HexDump.java b/src/java/org/apache/poi/util/HexDump.java index d45b239bf7..cbb27af7ab 100644 --- a/src/java/org/apache/poi/util/HexDump.java +++ b/src/java/org/apache/poi/util/HexDump.java @@ -296,6 +296,34 @@ public class HexDump return retVal.toString(); } + /** + *

Converts the parameter to a hex value breaking the results into + * lines.

+ * + * @param value The value to convert + * @param bytesPerLine The maximum number of bytes per line. The next byte + * will be written to a new line + * @return A String representing the array of bytes + */ + public static String toHex(final byte[] value, final int bytesPerLine) + { + StringBuffer retVal = new StringBuffer(); + retVal.append('['); + int i = -1; + for(int x = 0; x < value.length; x++) + { + if (++i == bytesPerLine) + { + retVal.append("\n "); + i = 0; + } + retVal.append(toHex(value[x])); + retVal.append(", "); + } + retVal.append(']'); + return retVal.toString(); + } + /** * Converts the parameter to a hex value. *