[Webfunds-commits] java/webfunds/sox Payment.java Utils.java DepositRequest.java

Ian Grigg iang@cypherpunks.ai
Sun, 11 Jun 2000 18:29:42 -0400 (AST)


iang        00/06/11 18:29:42

  Modified:    webfunds/utils Hex.java
               webfunds/sox Payment.java Utils.java DepositRequest.java
  Log:
  Moved printable to webfunds.utils.Hex as more general home.

Revision  Changes    Path
1.5       +23 -1     java/webfunds/utils/Hex.java

Index: Hex.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/utils/Hex.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Hex.java	2000/06/05 00:55:42	1.4
+++ Hex.java	2000/06/11 22:29:41	1.5
@@ -1,4 +1,4 @@
-/* $Id: Hex.java,v 1.4 2000/06/05 00:55:42 iang Exp $
+/* $Id: Hex.java,v 1.5 2000/06/11 22:29:41 iang Exp $
  *
  * Copyright 1995-1999 by Systemics, Ltd on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -103,6 +103,28 @@
     }
 
 
+
+    /**
+     *  Useful for printing descriptions, which can be binary.
+     *  @return a string that is printable, either the original, or a hex
+     *          conversion of the original if funny chars found.
+     */
+    public static String printable(byte[] data)
+    {
+        if (data == null)
+            return "<undef>";
+
+        int len = data.length;
+        for (int pos = 0; pos < len; pos++)
+        {
+            if (0x20 <= data[pos] && data[pos] <= 0xEF)
+                continue ;
+            if (data[pos] == '\r' || data[pos] == '\n' || data[pos] == '\t')
+                continue ;
+            return webfunds.utils.Hex.data2hex(data);
+        }
+        return new String(data);
+    }
 
 
 



1.19      +2 -2      java/webfunds/sox/Payment.java

Index: Payment.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Payment.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Payment.java	2000/06/05 00:54:30	1.18
+++ Payment.java	2000/06/11 22:29:41	1.19
@@ -1,5 +1,5 @@
 /*
- * $Id: Payment.java,v 1.18 2000/06/05 00:54:30 iang Exp $
+ * $Id: Payment.java,v 1.19 2000/06/11 22:29:41 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -381,7 +381,7 @@
         if (desc == null)
             retval += "  Desc: <none>\n";
         else
-            retval += "  Desc: "+Utils.printable(desc)+"\n";
+            retval += "  Desc: "+webfunds.utils.Hex.printable(desc)+"\n";
 
         return retval;
     }



1.14      +16 -77    java/webfunds/sox/Utils.java

Index: Utils.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Utils.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Utils.java	2000/06/10 22:37:15	1.13
+++ Utils.java	2000/06/11 22:29:42	1.14
@@ -1,5 +1,5 @@
 /*
- * $Id: Utils.java,v 1.13 2000/06/10 22:37:15 gelderen Exp $
+ * $Id: Utils.java,v 1.14 2000/06/11 22:29:42 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -64,69 +64,7 @@
 
 
 
-//    public static void main(String argv[])
-//        throws Exception
-//    {
-//        String s = "c001d00d";
-//        byte b[] = { (byte)0xC0, (byte)0x01, (byte)0xD0, (byte)0x0D };
-//
-//        String test = toHex(b).toLowerCase();
-//        if (!test.equals(s))
-//            throw new Exception("toHex " + s + " failed: " + test);
-//
-//        byte ttt[] = fromHex(s);
-//        // ttt[2] = (byte)0xFA;  // test
-//        for (int i = 0; i < b.length; i++)
-//        {
-//            if (ttt[i] != b[i])
-//                throw new Exception("fromHex " + s + " failed: "
-//                                + toHex(ttt) + " (byte " + i + ")");
-//        }
-//
-//        return ;
-//    }
-//
-//    public static String toHex(byte[] data)
-//    {
-//        int len = data.length;
-//        StringBuffer buf = new StringBuffer(len*2);
-//        for (int pos = 0; pos < len; pos++)
-//            buf.append(hex((data[pos]>>>4)&0x0F)).append(hex(data[pos]&0x0F));
-//        return buf.toString();
-//    }
-//
-//    public static byte[] fromHex(String str)
-//    {
-//        int len = str.length();    // probably should check length
-//        char hex[] = str.toCharArray();
-//        byte[] buf = new byte[len/2];
-//
-//        for (int pos = 0; pos < len / 2; pos++)
-//            buf[pos] = (byte)( ((data(hex[2*pos]) << 4) & 0xF0)
-//                            | ( data(hex[2*pos + 1])   & 0x0F) );
-//
-//        return buf;
-//    }
-//  
-//    private static char hex(int i)
-//    {
-//        if ((0 <= i) && (i <= 9 ))
-//            return (char)('0' + i);
-//        else
-//            return (char)('a' + (i-10));
-//    }
-//  
-//    private static byte data(char c)
-//    {
-//        if (('0' <= c) && (c <= '9' ))
-//            return (byte)((byte)c - (byte)'0');
-//        else if (('a' <= c) && (c <= 'f' ))
-//            return (byte)((byte)c - (byte)'a' + 10);
-//        else if (('A' <= c) && (c <= 'F' ))
-//            return (byte)((byte)c - (byte)'A' + 10);
-//        else
-//            return -1;
-//    }
+//  general Hex routines are in webfunds.utils.Hex.
 
     public static boolean byteEquals(byte[] one, byte[] two)
     {
@@ -255,17 +193,18 @@
          return pk;
     }
 
-    public static String printable(byte[] data)
-    {
-        int len = data.length;
-        for (int pos = 0; pos < len; pos++)
-        {
-            if (0x20 <= data[pos] && data[pos] <= 0xEF)
-                continue ;
-            if (data[pos] == '\r' || data[pos] == '\n' || data[pos] == '\t')
-                continue ;
-            return webfunds.utils.Hex.data2hex(data);
-        }
-        return new String(data);
-    }
+// moved to webfunds.utils.Hex
+//    public static String printable(byte[] data)
+//    {
+//        int len = data.length;
+//        for (int pos = 0; pos < len; pos++)
+//        {
+//            if (0x20 <= data[pos] && data[pos] <= 0xEF)
+//                continue ;
+//            if (data[pos] == '\r' || data[pos] == '\n' || data[pos] == '\t')
+//                continue ;
+//            return webfunds.utils.Hex.data2hex(data);
+//        }
+//        return new String(data);
+//    }
 }



1.21      +2 -2      java/webfunds/sox/DepositRequest.java

Index: DepositRequest.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/DepositRequest.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- DepositRequest.java	2000/05/28 02:59:56	1.20
+++ DepositRequest.java	2000/06/11 22:29:42	1.21
@@ -1,5 +1,5 @@
 /*
- * $Id: DepositRequest.java,v 1.20 2000/05/28 02:59:56 iang Exp $
+ * $Id: DepositRequest.java,v 1.21 2000/06/11 22:29:42 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -263,7 +263,7 @@
         if (depositDesc == null)
             retval += "\tDesc: <none>\n";
         else
-            retval += "\tDesc: "+Utils.printable(depositDesc)+"\n";
+            retval += "\tDesc: "+webfunds.utils.Hex.printable(depositDesc)+"\n";
         return retval;
     }