directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1601718 - /directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/mavibot/btree/SchemaAwareLdifReader.java
Date Tue, 10 Jun 2014 18:21:04 GMT
Author: kayyagari
Date: Tue Jun 10 18:21:03 2014
New Revision: 1601718

URL: http://svn.apache.org/r1601718
Log:
avoid creation of an ArrayList while we always send the LDIF string of a single entry

Modified:
    directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/mavibot/btree/SchemaAwareLdifReader.java

Modified: directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/mavibot/btree/SchemaAwareLdifReader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/mavibot/btree/SchemaAwareLdifReader.java?rev=1601718&r1=1601717&r2=1601718&view=diff
==============================================================================
--- directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/mavibot/btree/SchemaAwareLdifReader.java
(original)
+++ directory/apacheds/trunk/mavibot-partition/src/main/java/org/apache/directory/mavibot/btree/SchemaAwareLdifReader.java
Tue Jun 10 18:21:03 2014
@@ -19,11 +19,21 @@
  */
 package org.apache.directory.mavibot.btree;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.apache.directory.api.i18n.I18n;
 import org.apache.directory.api.ldap.model.entry.DefaultEntry;
 import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.ldif.LdapLdifException;
 import org.apache.directory.api.ldap.model.ldif.LdifEntry;
 import org.apache.directory.api.ldap.model.ldif.LdifReader;
 import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.api.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * TODO SchemaAwareLdifReader.
@@ -33,6 +43,8 @@ import org.apache.directory.api.ldap.mod
 public class SchemaAwareLdifReader extends LdifReader
 {
     private SchemaManager schemaManager;
+
+    private static final Logger LOG = LoggerFactory.getLogger( SchemaAwareLdifReader.class
);
     
     public SchemaAwareLdifReader( SchemaManager schemaManager ) throws Exception
     {
@@ -46,4 +58,56 @@ public class SchemaAwareLdifReader exten
         return new LdifEntry( entry );
     }
     
+    
+    /**
+     * 
+     * parse a single entry from the given LDIF text.
+     *
+     * @param ldif the LDIF string
+     * @return an LdifEntry
+     * @throws LdapLdifException
+     */
+    public LdifEntry parseLdifEntry( String ldif ) throws LdapLdifException
+    {
+        LOG.debug( "Starts parsing ldif buffer" );
+
+        if ( Strings.isEmpty( ldif ) )
+        {
+            return null;
+        }
+
+        BufferedReader reader = new BufferedReader( new StringReader( ldif ) );
+
+        try
+        {
+            this.reader = reader;
+
+            // First get the version - if any -
+            version = parseVersion();
+            return parseEntry();
+        }
+        catch ( LdapLdifException ne )
+        {
+            LOG.error( I18n.err( I18n.ERR_12069, ne.getLocalizedMessage() ) );
+            throw new LdapLdifException( I18n.err( I18n.ERR_12070 ), ne );
+        }
+        catch ( LdapException le )
+        {
+            throw new LdapLdifException( le.getMessage(), le );
+        }
+        finally
+        {
+            // Close the reader
+            try
+            {
+                reader.close();
+            }
+            catch ( IOException ioe )
+            {
+                throw new LdapLdifException( I18n.err( I18n.ERR_12024_CANNOT_CLOSE_FILE ),
ioe );
+            }
+
+        }
+    }
+
 }



Mime
View raw message