directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10093 - incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber
Date Mon, 19 Apr 2004 04:08:20 GMT
Author: akarasulu
Date: Sun Apr 18 21:08:18 2004
New Revision: 10093

Modified:
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
Log:
added convenience method to turn an int into a hex string

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/DefaultMutableTupleNode.java
Sun Apr 18 21:08:18 2004
@@ -25,6 +25,7 @@
 import java.util.Collections ;
 
 import org.apache.commons.lang.StringUtils ;
+import org.apache.commons.codec.binary.Hex;
 
 
 /**
@@ -303,7 +304,7 @@
     /**
      * Depth first generation of this tlv tuple node's encoded image.
      * 
-     * @see org.apache.snickers.ber.TupleNode#encode()
+     * @see org.apache.snickers.ber.TupleNode#encode(ByteBuffer)
      */
     public void encode( ByteBuffer dest )
     {
@@ -369,8 +370,28 @@
         printDepthFirst( buf, 0 ) ;
         return buf.toString() ;
     }
-    
-    
+
+
+    /**
+     * Gets the hex encoding of an integer with the most significant
+     * bites first.
+     *
+     * @param val the integer to break up into 4 bytes and hex encode
+     * @return the hex encoded 4 bytes of an integer
+     */
+    private String getHex( int val )
+    {
+        byte[] bites = new byte[4] ;
+
+        bites[0] = (byte) ( ( val & 0xff000000 ) >> 24 ) ;
+        bites[1] = (byte) ( ( val & 0x00ff0000 ) >> 16 ) ;
+        bites[2] = (byte) ( ( val & 0x0000ff00 ) >> 8  ) ;
+        bites[3] = (byte) (   val & 0x000000ff ) ;
+
+        return new String( Hex.encodeHex( bites ) ) ;
+    }
+
+
     /**
      * Generates a depth first traversal of this node.
      * 
@@ -388,7 +409,9 @@
         }
         
         buf.append( levelTab ).append( tuple.getId() ) ;
-        buf.append( ' ' ).append( tuple.typeClass ) ;
+        buf.append( " [" ).append( "0x" ) ;
+        buf.append( getHex( tuple.getRawPrimitiveTag() ) ) ;
+        buf.append( ']' ) ;
         buf.append( '[' ).append( tuple.length ).append( ']' ) ;
         for ( int ii = 0; ii < children.size(); ii++ )
         {

Mime
View raw message