You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/03/10 05:40:24 UTC
svn commit: rev 9333 - in incubator/directory/snickers/trunk/ber/src: java/org/apache/snickers/asn java/org/apache/snickers/ber java/org/apache/snickers/ber/util test/org/apache/snickers/ber
Author: akarasulu
Date: Tue Mar 9 20:40:24 2004
New Revision: 9333
Modified:
incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/asn/Primitive.java
incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERUtils.java
incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/util/TLVParsingUtility.java
incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/ObjectVersePrimitiveTest.java
Log:
add code lost in last failed checkin attempt and fixing misspellings
Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/asn/Primitive.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/asn/Primitive.java (original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/asn/Primitive.java Tue Mar 9 20:40:24 2004
@@ -57,7 +57,7 @@
* @author $Author$
* @version $Rev$
*/
-public interface Primative {
+public interface Primitive {
public final int BOOLEAN = 1;
public final int INTEGER = 2;
public final int BITSTRING = 3;
Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERUtils.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERUtils.java (original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BERUtils.java Tue Mar 9 20:40:24 2004
@@ -21,8 +21,6 @@
import org.apache.commons.codec.DecoderException ;
import org.apache.commons.collections.primitives.ArrayByteList ;
-import org.apache.commons.lang.NotImplementedException ;
-
/**
* Basic Encoding Rule (BER) utility functions.
@@ -216,8 +214,41 @@
}
- public static int getLength( ArrayByteList octets )
+ /**
+ * Decodes the length of a value for a tlv using the Length field bytes.
+ *
+ * @param octets the length field bytes in the TLV
+ * @return the length of the TLV
+ * @throws DecoderException if the precision cannot hold the number
+ */
+ public static int getLength( ArrayByteList octets ) throws DecoderException
{
- throw new NotImplementedException( "STUB" ) ;
+ if ( octets.size() >= 6 )
+ {
+ /*
+ * If this exception is ever thrown which is highly unlikely, then
+ * we need to switch to another data type to return because after
+ * 5 bytes the int can no longer hold the number.
+ */
+ throw new DecoderException( "Length number is too large." ) ;
+ }
+
+ // if we are using the short form then just return the first octet
+ if ( ( octets.get( 0 ) & Binary.BIT_7 ) == 0 )
+ {
+ return octets.get( 0 ) ;
+ }
+
+ // clear the id now
+ int length = 0 ;
+
+ // calculate tag value w/ long tag format
+ for( int ii = 1 ; ii < octets.size(); ii++ )
+ {
+ int shift = ( ii - 1 ) * 8 ;
+ length |= ( 0x00ff & ( int ) octets.get( ii ) ) << shift ;
+ }
+
+ return length ;
}
}
Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/util/TLVParsingUtility.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/util/TLVParsingUtility.java (original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/util/TLVParsingUtility.java Tue Mar 9 20:40:24 2004
@@ -54,7 +54,7 @@
import java.io.FileInputStream;
import org.apache.commons.codec.binary.*;
-import org.apache.snickers.asn.*;
+import org.apache.snickers.asn.Primitive;
import org.apache.snickers.ber.*;
/**
@@ -183,22 +183,22 @@
int value = 0;
switch( id ) {
- case Primative.BOOLEAN:
+ case Primitive.BOOLEAN:
boolean bVal = ( ((int)b[0] ) > 0 ) ? true : false;
System.out.println( strIndent + " BOOLEAN = " + true );
break;
- case Primative.INTEGER:
+ case Primitive.INTEGER:
for( int i = 0; i < len; i++ ) {
value = (value << 8) | (int)b[i];
}
System.out.println( strIndent + " INTEGER = " + value );
break;
- case Primative.OCTETSTRING:
+ case Primitive.OCTETSTRING:
String svalue = new String(b);
System.out.println( strIndent + " String = " + svalue );
break;
- case Primative.ENUMERATION:
+ case Primitive.ENUMERATION:
for( int i = 0; i < len; i++ ) {
value = (value << 8) | (int)b[i];
}
Modified: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/ObjectVersePrimitiveTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/ObjectVersePrimitiveTest.java (original)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/ObjectVersePrimitiveTest.java Tue Mar 9 20:40:24 2004
@@ -34,7 +34,7 @@
public class ObjectVersePrimitiveTest extends TestCase
{
public static final int MEMBER_COUNT = 3 ;
- public static final int INSTANCE_COUNT = 10000000 ;
+ public static final int INSTANCE_COUNT = 1000000 ;
public static final Class OBJECT_CLASS = Tuple.class ;
long objTime = 0 ;