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/01/26 07:50:22 UTC
svn commit: rev 6301 - in incubator/directory/snickers/trunk/ber: . src/java/org/apache/snickers/ber
Author: akarasulu
Date: Sun Jan 25 22:50:21 2004
New Revision: 6301
Added:
incubator/directory/snickers/trunk/ber/project.properties
incubator/directory/snickers/trunk/ber/project.xml
Modified:
incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/BerUtils.java
Log:
added some ByteBuffer overloads and project POM for Maven builds
Added: incubator/directory/snickers/trunk/ber/project.properties
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/project.properties Sun Jan 25 22:50:21 2004
@@ -0,0 +1,14 @@
+maven.javadoc.private=true
+maven.javadoc.customtags=tag1 tag2
+
+tag1.name=todo
+tag1.description=To Do:
+tag1.enabled=true
+tag1.scope=all
+
+tag2.name=task
+tag2.description=Task:
+tag2.enabled=false
+tag2.scope=all
+
+maven.license.licenseFile=../../../LICENSE.txt
Added: incubator/directory/snickers/trunk/ber/project.xml
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/project.xml Sun Jan 25 22:50:21 2004
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project>
+ <extend>${basedir}/../project.xml</extend>
+ <groupId>directory</groupId>
+ <id>snickers-ber-api</id>
+
+ <name>Snickers BER API</name>
+ <package>org.apache.snickers.ber</package>
+ <currentVersion>SNAPSHOT</currentVersion>
+ <inceptionYear>2004</inceptionYear>
+
+ <shortDescription>Snickers BER API</shortDescription>
+
+ <description>
+ API containing functionality used for encoding and decoding BER
+ streams both in blocking and non-blocking modes.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.0</version>
+ <url>http://jakarta.apache.org/commons/lang/api</url>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>SNAPSHOT</version>
+ <url>http://jakarta.apache.org/commons/codec</url>
+ </dependency>
+ </dependencies>
+</project>
+
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 Sun Jan 25 22:50:21 2004
@@ -50,6 +50,8 @@
package org.apache.snickers.ber ;
+import java.nio.ByteBuffer;
+
import org.apache.commons.codec.binary.Binary ;
import org.apache.commons.codec.DecoderException ;
@@ -142,6 +144,22 @@
/**
+ * Given a buffer this method returns the index of the last identifier
+ * octet (tag part of TLV). If the short format is used then the returned
+ * index is the given index parameter. If the long format is used, the
+ * returned index will be offset by one or more. The returned index is
+ * an octet of the identifier.
+ *
+ * @param a_buf a buffer of TLVs
+ * @return the index containing the last octet of the TLV's Tag/Identifier
+ */
+ public final static int getIdentifierEndIndex( byte[] a_buf )
+ {
+ return getIdentifierEndIndex( a_buf, 0 ) ;
+ }
+
+
+ /**
* Given a buffer and some TLV start index in it, this method returns the
* index of the last identifier octet (tag part of TLV). If the short
* format is used then the returned index is the given index parameter.
@@ -155,7 +173,6 @@
public final static int getIdentifierEndIndex( byte[] a_buf, int a_idx )
{
int l_end = a_idx ;
- byte[] l_octets = null ;
// get the last five bits only zero out others
int l_value = a_buf[a_idx] & SHORT_TAG_MASK ;
@@ -180,6 +197,59 @@
/**
+ * Given a buffer this method returns the index of the last identifier
+ * octet (tag part of TLV). If the short format is used then the returned
+ * index is the given index parameter. If the long format is used, the
+ * returned index will be offset by one or more. The returned index is
+ * an octet of the identifier.
+ *
+ * @param a_buf a buffer of TLVs
+ * @return the index containing the last octet of the TLV's Tag/Identifier
+ */
+ public final static int getIdentifierEndIndex( ByteBuffer a_buf )
+ {
+ return getIdentifierEndIndex( a_buf, 0 ) ;
+ }
+
+
+ /**
+ * Given a buffer and some TLV start index in it, this method returns the
+ * index of the last identifier octet (tag part of TLV). If the short
+ * format is used then the returned index is the given index parameter.
+ * If the long format is used, the returned index will be offset by one
+ * or more. The returned index is an octet of the identifier.
+ *
+ * @param a_buf a buffer of TLVs
+ * @param a_idx the start position of a TLV
+ * @return the index containing the last octet of the TLV's Tag/Identifier
+ */
+ public final static int getIdentifierEndIndex( ByteBuffer a_buf, int a_idx )
+ {
+ int l_end = a_idx ;
+
+ // get the last five bits only zero out others
+ int l_value = a_buf.get( a_idx ) & SHORT_TAG_MASK ;
+
+ // if bits are not all 1's then identifier is short return the index
+ if ( l_value != SHORT_TAG_MASK )
+ {
+ return a_idx ;
+ }
+
+ l_end++ ;
+ for ( ; l_end < a_buf.limit(); l_end++ )
+ {
+ if ( ( a_buf.get( l_end ) & Binary.BIT_7 ) == 0 )
+ {
+ return l_end ;
+ }
+ }
+
+ throw new IllegalStateException( "Should never get here!" ) ;
+ }
+
+
+ /**
* Gets the tag value of a TLV whether the short or long value encoding
* format is used.
*
@@ -211,6 +281,53 @@
// Calculate tag value w/ long tag format for 16384 > values > 127
l_value |= ( a_octets[2] & LONG_TAG_MASK ) << 7 ;
if ( ( a_octets[2] & Binary.BIT_7 ) == 0 )
+ {
+ return l_value ;
+ }
+
+ /*
+ * If this exception is ever thrown which is highly unlikely, then
+ * this method can be extended to use another 2 octets before the
+ * int return type must be changed to one that can hold the value.
+ */
+ throw new DecoderException( "Tag function only recognizes tag values of"
+ + " up to 16383. For larger values update the BerUtils.getTag"
+ + " function." ) ;
+ }
+
+
+ /**
+ * Gets the tag value of a TLV whether the short or long value encoding
+ * format is used.
+ *
+ * @param a_octets the set of octets needed to determine the tag value
+ * (a.k.a identifier octets)
+ * @return the value of the tag
+ * @throws DecoderException if the value cannot be determined due to
+ * type limitations of this method's return type.
+ */
+ public final static int getTagValue( ByteBuffer a_octets )
+ throws DecoderException
+ {
+ // get the last five bits only zero out others
+ int l_value = a_octets.get( 0 ) & SHORT_TAG_MASK ;
+
+ // if bits are not all 1's then return the value which is less than 31
+ if ( l_value != SHORT_TAG_MASK )
+ {
+ return l_value ;
+ }
+
+ // Calculate tag value w/ long tag format for 128 > values > 30
+ l_value = a_octets.get( 1 ) & LONG_TAG_MASK ;
+ if ( ( a_octets.get( 1 ) & Binary.BIT_7 ) == 0 )
+ {
+ return l_value ;
+ }
+
+ // Calculate tag value w/ long tag format for 16384 > values > 127
+ l_value |= ( a_octets.get( 2 ) & LONG_TAG_MASK ) << 7 ;
+ if ( ( a_octets.get( 2 ) & Binary.BIT_7 ) == 0 )
{
return l_value ;
}