directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r950975 - in /directory: apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ shared/trunk/ldap-ldif/src/main/java/org/apa...
Date Thu, 03 Jun 2010 12:13:44 GMT
Author: felixk
Date: Thu Jun  3 12:13:43 2010
New Revision: 950975

URL: http://svn.apache.org/viewvc?rev=950975&view=rev
Log:
Save string values larger than 64Kb - DIRSERVER-1319

Added:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/UTFUtils.java
  (with props)
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/UTFUtilsTest.java
  (with props)
Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEvent.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java
    directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntry.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntryAttribute.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultModification.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVA.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVASerializer.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DnSerializer.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnSerializer.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEvent.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEvent.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEvent.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/changelog/ChangeLogEvent.java
Thu Jun  3 12:13:43 2010
@@ -30,6 +30,7 @@ import java.util.List;
 import org.apache.directory.server.core.LdapPrincipal;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 
 
 /**
@@ -172,7 +173,7 @@ public class ChangeLogEvent implements E
         
         if ( hasZuluTime )
         {
-            zuluTime = in.readUTF();
+            zuluTime = UTFUtils.readUTF( in );
         }
         
         // Read the forward LDIF
@@ -219,7 +220,7 @@ public class ChangeLogEvent implements E
         if ( zuluTime != null )
         {
             out.writeBoolean( true );
-            out.writeUTF( zuluTime );
+            UTFUtils.writeUTF( out, zuluTime );
         }
         else
         {

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java
Thu Jun  3 12:13:43 2010
@@ -39,6 +39,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.name.DnSerializer;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -110,22 +111,22 @@ public class ReplicaEventMessage impleme
             modDnControl = new SyncModifyDnControl();
             modDnControl.setModDnType( modDnType );
             
-            modDnControl.setEntryDn( in.readUTF() );
+            modDnControl.setEntryDn( UTFUtils.readUTF( in ) );
             
             switch( modDnType )
             {
                 case MOVE:
-                    modDnControl.setNewSuperiorDn( in.readUTF() );
+                    modDnControl.setNewSuperiorDn( UTFUtils.readUTF( in ) );
                     break;
                    
                 case RENAME:
-                    modDnControl.setNewRdn( in.readUTF() );
+                    modDnControl.setNewRdn( UTFUtils.readUTF( in ) );
                     modDnControl.setDeleteOldRdn( in.readBoolean() );
                     break;
                     
                 case MOVEANDRENAME:
-                    modDnControl.setNewSuperiorDn( in.readUTF() );
-                    modDnControl.setNewRdn( in.readUTF() );
+                    modDnControl.setNewSuperiorDn( UTFUtils.readUTF( in ) );
+                    modDnControl.setNewRdn( UTFUtils.readUTF( in ) );
                     modDnControl.setDeleteOldRdn( in.readBoolean() );
             }
         }
@@ -148,7 +149,7 @@ public class ReplicaEventMessage impleme
         for ( int i = 0; i < nbAttributes; i++ )
         {
             // Read the attribute's OID
-            String oid = in.readUTF();
+            String oid = UTFUtils.readUTF( in );
 
             try
             {
@@ -180,22 +181,22 @@ public class ReplicaEventMessage impleme
             
             SyncModifyDnType modDnType = modDnControl.getModDnType();
             out.writeShort( modDnType.getValue() );
-            out.writeUTF( modDnControl.getEntryDn() );
+            UTFUtils.writeUTF( out, modDnControl.getEntryDn() );
             
             switch( modDnType )
             {
                 case MOVE:
-                    out.writeUTF( modDnControl.getNewSuperiorDn() );
+                    UTFUtils.writeUTF( out, modDnControl.getNewSuperiorDn() );
                     break;
                    
                 case RENAME:
-                    out.writeUTF( modDnControl.getNewRdn() );
+                    UTFUtils.writeUTF( out, modDnControl.getNewRdn() );
                     out.writeBoolean( modDnControl.isDeleteOldRdn() );
                     break;
                     
                 case MOVEANDRENAME:
-                    out.writeUTF( modDnControl.getNewSuperiorDn() );
-                    out.writeUTF( modDnControl.getNewRdn() );
+                    UTFUtils.writeUTF( out, modDnControl.getNewSuperiorDn() );
+                    UTFUtils.writeUTF( out, modDnControl.getNewRdn() );
                     out.writeBoolean( modDnControl.isDeleteOldRdn() );
             }
         }
@@ -221,7 +222,7 @@ public class ReplicaEventMessage impleme
             DefaultEntryAttribute attribute = ( DefaultEntryAttribute ) attrItr.next();
             // Write the oid to be able to restore the AttributeType when deserializing
             // the attribute
-            out.writeUTF( attribute.getAttributeType().getOid() );
+            UTFUtils.writeUTF( out, attribute.getAttributeType().getOid() );
 
             // Write the attribute
             attribute.serialize( out );

Modified: directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
(original)
+++ directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
Thu Jun  3 12:13:43 2010
@@ -43,6 +43,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.name.RDN;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 
 
 /**
@@ -836,12 +837,12 @@ public class LdifEntry implements Clonea
                 
                 if ( in.readBoolean() )
                 {
-                    newRdn = in.readUTF();
+                    newRdn = UTFUtils.readUTF( in );
                 }
                 
                 if ( in.readBoolean() )
                 {
-                    newSuperior = in.readUTF();
+                    newSuperior = UTFUtils.readUTF( in );
                 }
                 
                 break;
@@ -854,7 +855,7 @@ public class LdifEntry implements Clonea
                 for ( int i = 0; i < nbModifs; i++ )
                 {
                     int operation = in.readInt();
-                    String modStr = in.readUTF();
+                    String modStr = UTFUtils.readUTF( in );
                     DefaultEntryAttribute value = (DefaultEntryAttribute)in.readObject();
                     
                     addModificationItem( ModificationOperation.getOperation( operation ),
modStr, value );
@@ -903,7 +904,7 @@ public class LdifEntry implements Clonea
                 if ( newRdn != null )
                 {
                     out.writeBoolean( true );
-                    out.writeUTF( newRdn );
+                    UTFUtils.writeUTF( out, newRdn );
                 }
                 else
                 {
@@ -913,7 +914,7 @@ public class LdifEntry implements Clonea
                 if ( newSuperior != null )
                 {
                     out.writeBoolean( true );
-                    out.writeUTF( newSuperior );
+                    UTFUtils.writeUTF( out, newSuperior );
                 }
                 else
                 {
@@ -928,7 +929,7 @@ public class LdifEntry implements Clonea
                 for ( Modification modification:modificationList )
                 {
                     out.writeInt( modification.getOperation().getValue() );
-                    out.writeUTF( modification.getAttribute().getId() );
+                    UTFUtils.writeUTF( out, modification.getAttribute().getId() );
                     
                     EntryAttribute attribute = modification.getAttribute();
                     out.writeObject( attribute );

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntry.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntry.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntry.java
Thu Jun  3 12:13:43 2010
@@ -42,6 +42,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -2654,7 +2655,7 @@ public class DefaultEntry implements Ent
                 // the attribute
                 String oid = attributeType.getOid();
 
-                out.writeUTF( oid );
+                UTFUtils.writeUTF( out, oid );
 
                 // Get the attribute
                 DefaultEntryAttribute attribute = ( DefaultEntryAttribute ) attributes.get(
attributeType.getOid() );
@@ -2670,7 +2671,7 @@ public class DefaultEntry implements Ent
             {
                 // Write the id to be able to restore the AttributeType when deserializing
                 // the attribute
-                out.writeUTF( id );
+                UTFUtils.writeUTF( out, id );
 
                 // Get the attribute
                 DefaultEntryAttribute attribute = ( DefaultEntryAttribute ) attributes.get(
id );
@@ -2711,7 +2712,7 @@ public class DefaultEntry implements Ent
             for ( int i = 0; i < nbAttributes; i++ )
             {
                 // Read the attribute's OID
-                String oid = in.readUTF();
+                String oid = UTFUtils.readUTF( in );
 
                 try
                 {
@@ -2739,7 +2740,7 @@ public class DefaultEntry implements Ent
             for ( int i = 0; i < nbAttributes; i++ )
             {
                 // Read the attribute's ID
-                String id = in.readUTF();
+                String id = UTFUtils.readUTF( in );
 
                 // Create the attribute we will read
                 EntryAttribute attribute = new DefaultEntryAttribute( id );

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntryAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntryAttribute.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntryAttribute.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntryAttribute.java
Thu Jun  3 12:13:43 2010
@@ -36,6 +36,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -2428,7 +2429,7 @@ public class DefaultEntryAttribute imple
     public void serialize( ObjectOutput out ) throws IOException
     {
         // Write the UPId (the id will be deduced from the upID)
-        out.writeUTF( upId );
+        UTFUtils.writeUTF( out, upId );
         
         // Write the HR flag, if not null
         if ( isHR != null )
@@ -2471,7 +2472,7 @@ public class DefaultEntryAttribute imple
     public void deserialize( ObjectInput in ) throws IOException, ClassNotFoundException
     {
         // Read the ID and the UPId
-        upId = in.readUTF();
+        upId = UTFUtils.readUTF( in );
         
         // Compute the id
         setUpId( upId );
@@ -2530,7 +2531,7 @@ public class DefaultEntryAttribute imple
     public void writeExternal( ObjectOutput out ) throws IOException
     {
         // Write the UPId (the id will be deduced from the upID)
-        out.writeUTF( upId );
+        UTFUtils.writeUTF( out, upId );
         
         // Write the HR flag, if not null
         if ( isHR != null )
@@ -2566,7 +2567,7 @@ public class DefaultEntryAttribute imple
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
     {
         // Read the ID and the UPId
-        upId = in.readUTF();
+        upId = UTFUtils.readUTF( in );
         
         // Compute the id
         setUpId( upId );

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultModification.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultModification.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultModification.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultModification.java
Thu Jun  3 12:13:43 2010
@@ -27,6 +27,7 @@ import org.apache.directory.shared.i18n.
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -243,7 +244,7 @@ public class DefaultModification impleme
         AttributeType at = attribute.getAttributeType();
         
         // Write the attribute's oid
-        out.writeUTF( at.getOid() );
+        UTFUtils.writeUTF( out, at.getOid() );
         
         // Write the attribute
         ((DefaultEntryAttribute)attribute).serialize( out );
@@ -267,7 +268,7 @@ public class DefaultModification impleme
         operation = ModificationOperation.getOperation( op );
         
         // Read the attribute OID
-        String oid = in.readUTF();
+        String oid = UTFUtils.readUTF( in );
         
         // Lookup for tha associated AttributeType
         AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid );

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
Thu Jun  3 12:13:43 2010
@@ -19,10 +19,12 @@
 package org.apache.directory.shared.ldap.entry;
 
 
+import java.io.DataOutputStream;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
 
 import org.apache.directory.shared.ldap.exception.LdapException;
 
@@ -32,6 +34,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schema.LdapComparator;
 import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -501,7 +504,7 @@ public class StringValue extends Abstrac
         // Read the wrapped value, if it's not null
         if ( in.readBoolean() )
         {
-            wrappedValue = in.readUTF();
+            wrappedValue = UTFUtils.readUTF( in );
         }
         
         // Read the isNormalized flag
@@ -510,7 +513,7 @@ public class StringValue extends Abstrac
         if ( ( normalized ) && ( in.readBoolean() ) )
         {
             // Read the normalized value, if not null
-            normalizedValue = in.readUTF();
+            normalizedValue = UTFUtils.readUTF( in );
         }
         
         h = 0;
@@ -526,7 +529,7 @@ public class StringValue extends Abstrac
         if ( wrappedValue != null )
         {
             out.writeBoolean( true );
-            out.writeUTF( wrappedValue );
+            UTFUtils.writeUTF( out, wrappedValue );
         }
         else
         {
@@ -542,7 +545,7 @@ public class StringValue extends Abstrac
             if ( normalizedValue != null )
             {
                 out.writeBoolean( true );
-                out.writeUTF( normalizedValue );
+                UTFUtils.writeUTF( out, normalizedValue );
             }
             else
             {
@@ -584,7 +587,7 @@ public class StringValue extends Abstrac
             out.writeBoolean( true );
             
             // Write the data
-            out.writeUTF( wrappedValue );
+            UTFUtils.writeUTF( out, wrappedValue );
             
             // Normalize the data
             try
@@ -599,7 +602,7 @@ public class StringValue extends Abstrac
                 else
                 {
                     out.writeBoolean( false );
-                    out.writeUTF( normalizedValue );
+                    UTFUtils.writeUTF( out,  normalizedValue );
                 }
             }
             catch ( LdapException ne )
@@ -638,7 +641,7 @@ public class StringValue extends Abstrac
         }
         
         // Read the value
-        String wrapped = in.readUTF();
+        String wrapped = UTFUtils.readUTF( in );
         
         wrappedValue = wrapped;
         
@@ -657,7 +660,7 @@ public class StringValue extends Abstrac
             else
             {
                 // The normalized value is different. Read it
-                normalizedValue = in.readUTF();
+                normalizedValue = UTFUtils.readUTF( in );
             }
         }
     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVA.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVA.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVA.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVA.java
Thu Jun  3 12:13:43 2010
@@ -33,6 +33,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -856,11 +857,11 @@ public class AVA implements Cloneable, C
             throw new IOException( message );
         }
         
-        out.writeUTF( upName );
+        UTFUtils.writeUTF( out, upName );
         out.writeInt( start );
         out.writeInt( length );
-        out.writeUTF( upType );
-        out.writeUTF( normType );
+        UTFUtils.writeUTF( out, upType );
+        UTFUtils.writeUTF( out, normType );
         
         boolean isHR = !normValue.isBinary();
         
@@ -868,8 +869,8 @@ public class AVA implements Cloneable, C
         
         if ( isHR )
         {
-            out.writeUTF( upValue.getString() );
-            out.writeUTF( normValue.getString() );
+            UTFUtils.writeUTF( out, upValue.getString() );
+            UTFUtils.writeUTF( out, normValue.getString() );
         }
         else
         {
@@ -890,18 +891,18 @@ public class AVA implements Cloneable, C
      */
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
     {
-        upName = in.readUTF();
+        upName = UTFUtils.readUTF( in );
         start = in.readInt();
         length = in.readInt();
-        upType = in.readUTF();
-        normType = in.readUTF();
+        upType = UTFUtils.readUTF( in );
+        normType = UTFUtils.readUTF( in );
         
         boolean isHR = in.readBoolean();
         
         if ( isHR )
         {
-            upValue = new StringValue( in.readUTF() );
-            normValue = new StringValue( in.readUTF() );
+            upValue = new StringValue( UTFUtils.readUTF( in ) );
+            normValue = new StringValue( UTFUtils.readUTF( in ) );
         }
         else
         {

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVASerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVASerializer.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVASerializer.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AVASerializer.java
Thu Jun  3 12:13:43 2010
@@ -28,6 +28,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -114,11 +115,11 @@ public class AVASerializer
             throw new IOException( message );
         }
         
-        out.writeUTF( atav.getUpName() );
+        UTFUtils.writeUTF( out, atav.getUpName() );
         out.writeInt( atav.getStart() );
         out.writeInt( atav.getLength() );
-        out.writeUTF( atav.getUpType() );
-        out.writeUTF( atav.getNormType() );
+        UTFUtils.writeUTF( out, atav.getUpType() );
+        UTFUtils.writeUTF( out, atav.getNormType() );
         
         boolean isHR = !atav.getNormValue().isBinary();
         
@@ -126,8 +127,8 @@ public class AVASerializer
         
         if ( isHR )
         {
-            out.writeUTF( atav.getUpValue().getString() );
-            out.writeUTF( atav.getNormValue().getString() );
+            UTFUtils.writeUTF( out, atav.getUpValue().getString() );
+            UTFUtils.writeUTF( out, atav.getNormValue().getString() );
         }
         else
         {
@@ -152,11 +153,11 @@ public class AVASerializer
      */
     public static AVA deserialize( ObjectInput in ) throws IOException
     {
-        String upName = in.readUTF();
+        String upName = UTFUtils.readUTF( in );
         in.readInt(); // start
         in.readInt(); // length
-        String upType = in.readUTF();
-        String normType = in.readUTF();
+        String upType = UTFUtils.readUTF( in );
+        String normType = UTFUtils.readUTF( in );
         
         boolean isHR = in.readBoolean();
 
@@ -164,8 +165,8 @@ public class AVASerializer
         {
             if ( isHR )
             {
-                Value<String> upValue = new StringValue( in.readUTF() );
-                Value<String> normValue = new StringValue( in.readUTF() );
+                Value<String> upValue = new StringValue( UTFUtils.readUTF( in ) );
+                Value<String> normValue = new StringValue( UTFUtils.readUTF( in ) );
                 
                 AVA atav = 
                     new AVA( upType, normType, upValue, normValue, upName );

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
Thu Jun  3 12:13:43 2010
@@ -43,6 +43,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -1595,18 +1596,18 @@ public class DN implements Cloneable, Se
         }
         
         // Write the UPName
-        out.writeUTF( upName );
+        UTFUtils.writeUTF( out, upName );
         
         // Write the NormName if different
         if ( isNormalized() )
         {
             if ( upName.equals( normName ) )
             {
-                out.writeUTF( "" );
+                UTFUtils.writeUTF( out, "" );
             }
             else
             {
-                out.writeUTF( normName );
+                UTFUtils.writeUTF( out, normName );
             }
         }
         else
@@ -1643,10 +1644,10 @@ public class DN implements Cloneable, Se
     public void readExternal( ObjectInput in ) throws IOException , ClassNotFoundException
     {
         // Read the UPName
-        upName = in.readUTF();
+        upName = UTFUtils.readUTF( in );
         
         // Read the NormName
-        normName = in.readUTF();
+        normName = UTFUtils.readUTF( in );
         
         if ( normName.length() == 0 )
         {

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DnSerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DnSerializer.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DnSerializer.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DnSerializer.java
Thu Jun  3 12:13:43 2010
@@ -25,6 +25,7 @@ import java.io.ObjectOutput;
 
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,18 +67,18 @@ public class DnSerializer
         }
         
         // Write the UPName
-        out.writeUTF( dn.getName() );
+        UTFUtils.writeUTF( out, dn.getName() );
         
         // Write the NormName if different
         if ( dn.isNormalized() )
         {
             if ( dn.getName().equals( dn.getNormName() ) )
             {
-                out.writeUTF( "" );
+                UTFUtils.writeUTF( out, "" );
             }
             else
             {
-                out.writeUTF( dn.getNormName() );
+                UTFUtils.writeUTF( out, dn.getNormName() );
             }
         }
         else
@@ -115,10 +116,10 @@ public class DnSerializer
     public static DN deserialize( ObjectInput in ) throws IOException
     {
         // Read the UPName
-        String upName = in.readUTF();
+        String upName = UTFUtils.readUTF( in );
         
         // Read the NormName
-        String normName = in.readUTF();
+        String normName = UTFUtils.readUTF( in );
         
         if ( normName.length() == 0 )
         {

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RDN.java
Thu Jun  3 12:13:43 2010
@@ -38,6 +38,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -1353,15 +1354,15 @@ public class RDN implements Cloneable, C
     public void writeExternal( ObjectOutput out ) throws IOException
     {
         out.writeInt( nbAtavs );
-        out.writeUTF( upName );
+        UTFUtils.writeUTF( out, upName );
 
         if ( upName.equals( normName ) )
         {
-            out.writeUTF( "" );
+            UTFUtils.writeUTF( out, "" );
         }
         else
         {
-            out.writeUTF( normName );
+            UTFUtils.writeUTF( out, normName );
         }
 
         out.writeInt( start );
@@ -1404,10 +1405,10 @@ public class RDN implements Cloneable, C
         nbAtavs = in.readInt();
 
         // Read the UPName
-        upName = in.readUTF();
+        upName = UTFUtils.readUTF( in );
 
         // Read the normName
-        normName = in.readUTF();
+        normName = UTFUtils.readUTF( in );
 
         if ( StringTools.isEmpty( normName ) )
         {

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnSerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnSerializer.java?rev=950975&r1=950974&r2=950975&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnSerializer.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnSerializer.java
Thu Jun  3 12:13:43 2010
@@ -24,6 +24,7 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.ldap.util.UTFUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -63,8 +64,8 @@ public class RdnSerializer
     public static void serialize( RDN rdn, ObjectOutput out ) throws IOException
     {
         out.writeInt( rdn.getNbAtavs() );
-        out.writeUTF( rdn.getName() );
-        out.writeUTF( rdn.getNormName() );
+        UTFUtils.writeUTF( out, rdn.getName() );
+        UTFUtils.writeUTF( out, rdn.getNormName() );
         out.writeInt( rdn.getStart() );
         out.writeInt( rdn.getLength() );
         
@@ -105,10 +106,10 @@ public class RdnSerializer
         int nbAtavs = in.readInt();
         
         // Read the UPName
-        String upName = in.readUTF();
+        String upName = UTFUtils.readUTF( in );
         
         // Read the normName
-        String normName = in.readUTF();
+        String normName = UTFUtils.readUTF( in );
         
         if ( StringTools.isEmpty( normName ) )
         {

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/UTFUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/UTFUtils.java?rev=950975&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/UTFUtils.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/UTFUtils.java
Thu Jun  3 12:13:43 2010
@@ -0,0 +1,134 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.util;
+
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+
+public class UTFUtils
+{
+
+    /**
+     * In UTF every char may have 1-3 bytes size
+     * Max writeUTF bytes / max char symbol size
+     */
+    public static final int SPLIT_SIZE = 65535 / 3;
+
+
+    /**
+     * 
+     * Do writeUTF a string regardless of it's length. null value will be written with length=0
and value 'null' to
+     * recognize when reading if it's an empty string or a null string
+     *
+     * @param objectOutput The objectOutput to write to
+     * @param str The value to write
+     * @throws IOException If the value can't be written to the file
+     */
+    public static void writeUTF( ObjectOutput objectOutput, String str ) throws IOException
+    {
+
+        if ( str == null )
+        {
+            objectOutput.writeInt( 0 );
+            objectOutput.writeUTF( "null" );
+        }
+        else
+        {
+            int strLength = str.length();
+            int iterations = strLength / SPLIT_SIZE;
+
+            // Length of string
+            objectOutput.writeInt( strLength );
+
+            if ( iterations == 0 )
+            {
+                // String too short, no iterations needed, just write it
+                objectOutput.writeUTF( str );
+            }
+            else
+            {
+                if ( strLength % SPLIT_SIZE > 0 )
+                {
+                    ++iterations;
+                }
+
+                for ( int i = 0; i < iterations; ++i )
+                {
+                    int beginIndex = i * SPLIT_SIZE;
+                    int lastIndex = beginIndex + SPLIT_SIZE;
+
+                    if ( lastIndex > strLength )
+                    {
+                        objectOutput.writeUTF( str.substring( beginIndex, strLength ) );
+                    }
+                    else
+                    {
+                        objectOutput.writeUTF( str.substring( beginIndex, lastIndex ) );
+                    }
+                }
+            }
+        }
+    }
+
+
+    /**
+     * 
+     * Do readUTF a string regardless of it's length. null value is written with length=0
and value 'null' to
+     * recognize when reading if it's an empty string or a null string
+     *
+     * @param objectInput The objectInput to read from
+     * @return The value
+     * @throws IOException If the vale can't be read
+     */
+    public static String readUTF( ObjectInput objectInput ) throws IOException
+    {
+        StringBuffer stringBuffer = null;
+        int strLength = objectInput.readInt();
+
+        if ( strLength == 0 )
+        {
+            stringBuffer = new StringBuffer( objectInput.readUTF() );
+            if ( stringBuffer.toString().equals( "null" ) )
+            {
+                return null;
+            }
+        }
+        else
+        {
+            int iterations = strLength / SPLIT_SIZE;
+
+            if ( strLength % SPLIT_SIZE > 0 )
+            {
+                ++iterations;
+            }
+
+            stringBuffer = new StringBuffer( strLength );
+            for ( int i = 0; i < iterations; ++i )
+            {
+                stringBuffer.append( objectInput.readUTF() );
+            }
+        }
+        return stringBuffer.toString();
+    }
+
+}

Propchange: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/UTFUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/UTFUtils.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/UTFUtilsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/UTFUtilsTest.java?rev=950975&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/UTFUtilsTest.java
(added)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/UTFUtilsTest.java
Thu Jun  3 12:13:43 2010
@@ -0,0 +1,129 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.util;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Arrays;
+
+import org.junit.Test;
+
+
+/**
+ * A test case for the UTFUtils methods 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class UTFUtilsTest
+{
+
+    private FileOutputStream fos = null;
+    private FileInputStream fis = null;
+
+
+    /**
+     * 
+     * Creates a new instance of UTFUtilsTest.
+     *
+     */
+    public UTFUtilsTest()
+    {
+        try
+        {
+            File tmpFile = File.createTempFile( "UTFUtils", "test" );
+            tmpFile.deleteOnExit();
+            fos = new FileOutputStream( tmpFile );
+            fis = new FileInputStream( tmpFile );
+        }
+        catch ( IOException e )
+        {
+        }
+    }
+
+
+    /**
+     * 
+     * Test write/read of a null string
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testNullString() throws Exception
+    {
+        ObjectOutputStream dos = new ObjectOutputStream( fos );
+        ObjectInputStream dis = new ObjectInputStream( fis );
+        String testString = null;
+        UTFUtils.writeUTF( dos, testString );
+        dos.flush();
+        dos.close();
+        assertEquals( testString, UTFUtils.readUTF( dis ) );
+        dis.close();
+    }
+
+
+    /**
+     * 
+     * Test write/read of an empty string
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testEmptyString() throws Exception
+    {
+        ObjectOutputStream dos = new ObjectOutputStream( fos );
+        ObjectInputStream dis = new ObjectInputStream( fis );
+        String testString = "";
+        UTFUtils.writeUTF( dos, testString );
+        dos.flush();
+        dos.close();
+        assertEquals( testString, UTFUtils.readUTF( dis ) );
+        dis.close();
+    }
+
+
+    /**
+     * 
+     * Test write/read of a large string (> 64Kb)
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testLargeString() throws Exception
+    {
+        ObjectOutputStream dos = new ObjectOutputStream( fos );
+        ObjectInputStream dis = new ObjectInputStream( fis );
+        char[] fill = new char[196622]; // 65535 * 3 + 17
+        Arrays.fill( fill, '\u00fc' ); // German &&uuml
+        String testString = new String( fill );
+        UTFUtils.writeUTF( dos, testString );
+        dos.flush();
+        dos.close();
+        assertEquals( testString, UTFUtils.readUTF( dis ) );
+        dis.close();
+    }
+}

Propchange: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/UTFUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/UTFUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message