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 2005/04/15 07:40:54 UTC
svn commit: r161399 -
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapString.java
Author: elecharny
Date: Thu Apr 14 22:40:53 2005
New Revision: 161399
URL: http://svn.apache.org/viewcvs?view=rev&rev=161399
Log:
The LdapString.parse method returns a MutableString instead of a String
Modified:
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapString.java
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapString.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapString.java?view=diff&r1=161398&r2=161399
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapString.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/primitives/LdapString.java Thu Apr 14 22:40:53 2005
@@ -16,11 +16,12 @@
*/
package org.apache.asn1.ldap.codec.primitives;
-import org.apache.asn1.ber.tlv.Value;
import org.apache.asn1.ldap.codec.DecoderException;
-
-import java.io.UnsupportedEncodingException;
-
+import org.apache.asn1.util.MutableString;
+import org.apache.asn1.util.StringUtils;
+import org.apache.asn1.util.pools.LocalPoolManager;
+import org.apache.asn1.util.pools.PoolException;
+import org.apache.asn1.util.pools.PoolManager;
/**
* Decodes a LdapString, and checks that the character set used comply
@@ -34,24 +35,34 @@
//~ Methods ------------------------------------------------------------------------------------
/**
- * Transform the byte array to a String. A check is done to insure that
- * it complies with RFC 2279.
+ * Transform a byte array to a MutableString. The byte array contains
+ * an UTF-8 representation of a String
*
- * @param value The byte array to transform
- * @return A String that represent the LDAPSTRING
+ * @param pool The pool in which we will get a MutableSTring
+ * @param bytes The byte buffer that contains the LDAPSTRING
+ * @return A MutableString containing the LDAPSTRING
*
* @throws DecoderException If the byte array does not comply with RFC 2279
*/
- public static String parse( Value value ) throws DecoderException
+ public static MutableString parse( PoolManager pool, byte[] bytes ) throws DecoderException
{
+ if ( ( bytes == null ) || ( bytes.length == 0 ) )
+ {
+ return MutableString.EMPTY_STRING;
+ }
- try
+ int stringLength = StringUtils.countChars(bytes);
+
+ try
{
- return new String( value.getData(), "UTF-8" );
+ MutableString string = (MutableString)(((LocalPoolManager)pool).allocateString(stringLength));
+ string.setData(bytes);
+
+ return string;
}
- catch ( UnsupportedEncodingException uee )
+ catch (PoolException pe)
{
- throw new DecoderException( "Error while decoding the string" );
+ throw new DecoderException("Cannot allocate a LdapString");
}
}
}