You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/01/30 13:32:59 UTC

svn commit: r373501 - /directory/trunks/asn1/src/main/java/org/apache/asn1/ber/tlv/Value.java

Author: elecharny
Date: Mon Jan 30 04:32:56 2006
New Revision: 373501

URL: http://svn.apache.org/viewcvs?rev=373501&view=rev
Log:
- Added a method to encode integer with a tag if it's not an universal tag
- Simplified the generation of integers

Modified:
    directory/trunks/asn1/src/main/java/org/apache/asn1/ber/tlv/Value.java

Modified: directory/trunks/asn1/src/main/java/org/apache/asn1/ber/tlv/Value.java
URL: http://svn.apache.org/viewcvs/directory/trunks/asn1/src/main/java/org/apache/asn1/ber/tlv/Value.java?rev=373501&r1=373500&r2=373501&view=diff
==============================================================================
--- directory/trunks/asn1/src/main/java/org/apache/asn1/ber/tlv/Value.java (original)
+++ directory/trunks/asn1/src/main/java/org/apache/asn1/ber/tlv/Value.java Mon Jan 30 04:32:56 2006
@@ -382,7 +382,35 @@
         try
         {
             buffer.put( UniversalTag.INTEGER_TAG );
-            buffer.put( Length.getBytes( getNbBytes( value ) ) );
+            buffer.put( (byte)getNbBytes( value ) );
+            buffer.put( getBytes( value ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return;
+    }
+
+    /**
+     * Encode an integer value 
+     * 
+     * @param buffer The PDU in which the value will be put
+     * @param tag The tag if it's not an UNIVERSAL one
+     * @param value The integer to be encoded
+     */
+    public static void encode( ByteBuffer buffer, byte tag, int value ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try
+        {
+            buffer.put( tag );
+            buffer.put( (byte)getNbBytes( value ) );
             buffer.put( getBytes( value ) );
         }
         catch ( BufferOverflowException boe )