directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r226664 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java
Date Sun, 31 Jul 2005 17:26:03 GMT
Author: elecharny
Date: Sun Jul 31 10:26:00 2005
New Revision: 226664

URL: http://svn.apache.org/viewcvs?rev=226664&view=rev
Log:
Added a method to encode boolean values

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=226664&r1=226663&r2=226664&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 Sun
Jul 31 10:26:00 2005
@@ -40,6 +40,9 @@
 
     /** The current position of the last byte in the data buffer */
     private int    currentPos;
+    
+    private static final byte[] ENCODED_TRUE = new byte[] { 0x01, 0x01, (byte)0xFF};
+    private static final byte[] ENCODED_FALSE = new byte[] { 0x01, 0x01, (byte)0x00};
 
     //~ Methods ------------------------------------------------------------------------------------
 
@@ -257,7 +260,7 @@
      * Encode an integer value 
      * 
      * @param buffer The PDU in which the value will be put
-     * @param string The interger to be encoded
+     * @param value The integer to be encoded
      */
     public static void encode( ByteBuffer buffer, int value ) throws EncoderException
     {
@@ -271,6 +274,31 @@
             buffer.put( LdapConstants.INTEGER_TAG );
             buffer.put( Length.getBytes( Length.getNbBytes( value ) ) );
             buffer.put( getBytes( value ) );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        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 EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try
+        {
+            buffer.put( bool ? ENCODED_TRUE : ENCODED_FALSE ) ;
         }
         catch ( BufferOverflowException boe )
         {



Mime
View raw message