directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r225417 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java
Date Tue, 26 Jul 2005 23:35:08 GMT
Author: elecharny
Date: Tue Jul 26 16:35:05 2005
New Revision: 225417

URL: http://svn.apache.org/viewcvs?rev=225417&view=rev
Log:
Added a static method to compute the length of an integer value.

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java?rev=225417&r1=225416&r2=225417&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java Tue
Jul 26 16:35:05 2005
@@ -138,6 +138,41 @@
     }
 
     /**
+     * Utility function that return the number of bytes necessary to store 
+     * the value
+     * @param value The value to store in a byte array
+     * @return The number of bytes necessary to store the value.
+     */
+    public static int getNbBytes( int value )
+    {
+
+        if ( value >= 0 )
+        {
+
+            if ( value < 256 )
+            {
+                return 1;
+            }
+            else if ( value < 65536 )
+            {
+                return 2;
+            }
+            else if ( value < 16777216 )
+            {
+                return 3;
+            }
+            else
+            {
+                return 4;
+            }
+        }
+        else
+        {
+            return 4;
+        }
+    }
+    
+    /**
      * Return a string representing the Value
      *
      * @return A string representing the value



Mime
View raw message