You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by kl...@apache.org on 2003/08/23 16:49:35 UTC
cvs commit: jakarta-poi/src/java/org/apache/poi/util HexDump.java
klute 2003/08/23 07:49:35
Modified: src/java/org/apache/poi/util HexDump.java
Log:
Added a method for a formatted hex dump.
Revision Changes Path
1.10 +28 -0 jakarta-poi/src/java/org/apache/poi/util/HexDump.java
Index: HexDump.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/util/HexDump.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- HexDump.java 30 Jun 2003 12:20:55 -0000 1.9
+++ HexDump.java 23 Aug 2003 14:49:35 -0000 1.10
@@ -297,6 +297,34 @@
}
/**
+ * <p>Converts the parameter to a hex value breaking the results into
+ * lines.</p>
+ *
+ * @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.
*
* @param value The value to convert
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org