directory-commits mailing list archives

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

URL: http://svn.apache.org/viewcvs?rev=226667&view=rev
Log:
Added a method to encode an OctetString

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=226667&r1=226666&r2=226667&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:45:54 2005
@@ -18,6 +18,7 @@
 
 import org.apache.asn1.EncoderException;
 import org.apache.asn1.ldap.codec.LdapConstants;
+import org.apache.asn1.primitives.OctetString;
 import org.apache.asn1.util.MutableString;
 import org.apache.asn1.util.StringUtils;
 
@@ -223,6 +224,37 @@
         }
 
         return bytes;
+    }
+
+    /**
+     * Encode an OctetString value 
+     * 
+     * @param buffer The PDU in which the value will be put
+     * @param string The OctetString to be encoded
+     */
+    public static void encode( ByteBuffer buffer, OctetString string ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            buffer.put( LdapConstants.OCTET_STRING_TAG );
+            buffer.put( Length.getBytes( string.getLength() ) );
+    
+            if ( string.getLength() != 0 )
+            {
+                buffer.put( string.getValue() );
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return;
     }
 
     /**



Mime
View raw message