directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r226688 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java
Date Sun, 31 Jul 2005 20:13:35 GMT
Author: elecharny
Date: Sun Jul 31 13:13:32 2005
New Revision: 226688

URL: http://svn.apache.org/viewcvs?rev=226688&view=rev
Log:
Added a method to encode String 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=226688&r1=226687&r2=226688&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 13:13:32 2005
@@ -227,6 +227,39 @@
     }
 
     /**
+     * Encode an String value 
+     * 
+     * @param buffer The PDU in which the value will be put
+     * @param string The String to be encoded
+     */
+    public static void encode( ByteBuffer buffer, String string ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            buffer.put( LdapConstants.OCTET_STRING_TAG );
+            byte[] value = string.getBytes();
+            
+            buffer.put( Length.getBytes( value.length ) );
+    
+            if ( value.length != 0 )
+            {
+                buffer.put( value );
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return;
+    }
+
+    /**
      * Encode an OctetString value 
      * 
      * @param buffer The PDU in which the value will be put



Mime
View raw message