Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 65010 invoked from network); 9 Oct 2005 13:43:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Oct 2005 13:43:33 -0000 Received: (qmail 97761 invoked by uid 500); 9 Oct 2005 13:43:32 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 97734 invoked by uid 500); 9 Oct 2005 13:43:32 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 97719 invoked by uid 99); 9 Oct 2005 13:43:32 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 09 Oct 2005 06:43:32 -0700 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 09 Oct 2005 06:43:35 -0700 Received: (qmail 64970 invoked by uid 65534); 9 Oct 2005 13:43:11 -0000 Message-ID: <20051009134311.64969.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r307425 - /directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/LdapString.java Date: Sun, 09 Oct 2005 13:43:11 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 Apache Directory Project */ -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; } }