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/09/09 02:55:16 UTC

svn commit: r441707 - /directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java

Author: elecharny
Date: Fri Sep  8 17:55:15 2006
New Revision: 441707

URL: http://svn.apache.org/viewvc?view=rev&rev=441707
Log:
Added the encode(Boolean) method

Modified:
    directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java

Modified: directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java?view=diff&rev=441707&r1=441706&r2=441707
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java (original)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java Fri Sep  8 17:55:15 2006
@@ -81,6 +81,21 @@
             {0x78}, {0x79}, {0x7A}, {0x7B}, {0x7C}, {0x7D}, {0x7E}, {0x7F}
         };
     
+    /** The encoded byte for a TRUE value */
+    public static final byte TRUE_VALUE = ( byte ) 0xFF;
+
+    /** The encoded byte for a FALSE value */
+    public static final byte FALSE_VALUE = ( byte ) 0x00;
+
+    /** Pre-encoded PDUs for a TRUE and FALSE TLV */
+    private static final byte[] ENCODED_TRUE = new byte[]
+        { 0x01, 0x01, TRUE_VALUE };
+
+    private static final byte[] ENCODED_FALSE = new byte[]
+        { 0x01, 0x01, FALSE_VALUE };
+
+    
+    
     /**
      * Utility function that return the number of bytes necessary to store an
      * integer value. Note that this value must be in [Integer.MIN_VALUE,
@@ -231,4 +246,30 @@
 
         return;
     }
+    
+    /**
+     * Encode a boolean value
+     * 
+     * @param buffer The PDU in which the value will be put
+     * @param bool The boolean to be encoded
+     */
+    public static void encode( ByteBuffer buffer, boolean bool ) throws ValueException
+    {
+        if ( buffer == null )
+        {
+            throw new ValueException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try
+        {
+            buffer.put( bool ? ENCODED_TRUE : ENCODED_FALSE );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new ValueException( "The PDU buffer size is too small !" );
+        }
+
+        return;
+    }
+    
 }