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/10/09 15:43:11 UTC
svn commit: r307425 -
/directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java
Author: elecharny
Date: Sun Oct 9 06:43:07 2005
New Revision: 307425
URL: http://svn.apache.org/viewcvs?rev=307425&view=rev
Log:
As the MutableString class has been deleted, LdapString now implements the associated
behavior.
Modified:
directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java
Modified: directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java?rev=307425&r1=307424&r2=307425&view=diff
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java (original)
+++ directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java Sun Oct 9 06:43:07 2005
@@ -16,20 +16,27 @@
*/
package org.apache.asn1new.ldap.codec.primitives;
-import org.apache.asn1.codec.DecoderException;
-import org.apache.asn1new.util.MutableString;
+import java.io.UnsupportedEncodingException;
/**
* Decodes a LdapString, and checks that the character set used comply
* the ISO 10646 encoded following the UTF-8 algorithm (RFC 2044, RFC 2279)
- * .
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class LdapString extends MutableString
+public class LdapString
{
/** A null LdapString */
public transient static final LdapString EMPTY_STRING = new LdapString();
+
+ /** A null LdapString */
+ public transient static final byte[] EMPTY_BYTES = new byte[]{};
+
+ /** The inner String containing the LdapString */
+ protected String string;
+
+ /** The internal bytes representation of the LdapString */
+ protected byte[] bytes;
/**
* Construct an empty LdapString
@@ -37,32 +44,68 @@
*/
public LdapString()
{
- super( 0, false );
+ bytes = EMPTY_BYTES;
+ string = "";
}
//~ Methods ------------------------------------------------------------------------------------
/**
- * Transform a byte array to a MutableString. The byte array contains
- * an UTF-8 representation of a String
+ * Transform a byte array to a String. The byte array contains
+ * an UTF-8 representation of a String.
*
* @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
+ * @throws LdapStringEncodingException If the byte array is not a UTF-8 encoded
+ * ISO-10646 (Unicode) compatible String.
*/
- public LdapString( byte[] bytes ) throws DecoderException
+ public LdapString( byte[] bytes ) throws LdapStringEncodingException
{
- init( bytes );
+ try
+ {
+ string = new String( bytes, "UTF-8" );
+ this.bytes = new byte[ bytes.length ];
+
+ System.arraycopy( bytes, 0, this.bytes, 0, bytes.length );
+ }
+ catch ( UnsupportedEncodingException uee )
+ {
+ throw new LdapStringEncodingException( "The byte array is not an UTF-8 encoded Unicode String : " + uee.getMessage() );
+ }
}
- protected void init( byte[] bytes ) throws DecoderException
+ /**
+ * Get the LdapString as a String
+ * @return The string.
+ */
+ public String getString()
{
- if ( bytes == null )
- {
- return;
- }
-
- setData(bytes);
+ return string;
+ }
+
+ /**
+ * Get the content of the LdapString, as a byte array;
+ * @return A byte array of the LdapString string
+ */
+ public byte[] getBytes()
+ {
+ return bytes;
+ }
+
+ /**
+ * Get the size of the UTF-8 encoded string
+ * @return A number of bytes
+ */
+ public int getNbBytes()
+ {
+ return ( bytes != null ? bytes.length : 0 );
+ }
+
+ /**
+ * Return the string representation of a LdapString
+ */
+ public String toString()
+ {
+ return string;
}
}