[Webfunds-commits] java/webfunds/utils Hex.java

Ian Grigg iang@cypherpunks.ai
Sun, 4 Jun 2000 20:55:42 -0400 (AST)


iang        00/06/04 20:55:42

  Modified:    webfunds/utils Hex.java
  Log:
  more explicit null string, new call for binary debug

Revision  Changes    Path
1.4       +22 -2     java/webfunds/utils/Hex.java

Index: Hex.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/utils/Hex.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Hex.java	1999/12/29 03:56:50	1.3
+++ Hex.java	2000/06/05 00:55:42	1.4
@@ -1,4 +1,4 @@
-/* $Id: Hex.java,v 1.3 1999/12/29 03:56:50 iang Exp $
+/* $Id: Hex.java,v 1.4 2000/06/05 00:55:42 iang Exp $
  *
  * Copyright 1995-1999 by Systemics, Ltd on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -37,7 +37,7 @@
     public static String data2hex(byte[] data)
     {
         if (data == null)
-            return new String("");
+            return NULL;
 
         int len = data.length;
         StringBuffer buf = new StringBuffer(len*2);
@@ -80,6 +80,26 @@
             return (byte)((byte)c - (byte)'A' + 10);
         else
             return -1;
+    }
+
+    static final String NULL = "<null>";
+
+    /**
+     * @return a byte array converted to hex, and truncated beyond some
+     *         reasonable length, long enough to avoid debugging collisions.
+     */
+    public static String quick(byte[] b)
+    {
+        if (b == null)
+            return NULL;
+        if (b.length < 8)
+            return data2hex(b);
+
+        byte[] bbb = new byte[8];
+        for (int j = 0; j < bbb.length; j++)
+            bbb[j] = b[j];
+
+        return data2hex(bbb) + "...";
     }