directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r491281 - /directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
Date Sat, 30 Dec 2006 18:34:04 GMT
Author: elecharny
Date: Sat Dec 30 10:34:04 2006
New Revision: 491281

URL: http://svn.apache.org/viewvc?view=rev&rev=491281
Log:
The iterator next() method now thows a NoSuchElementException
Added a 'finally' to release file resource

Modified:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java?view=diff&rev=491281&r1=491280&r2=491281
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
Sat Dec 30 10:34:04 2006
@@ -37,6 +37,7 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.NoSuchElementException;
 
 import javax.naming.InvalidNameException;
 import javax.naming.NamingException;
@@ -625,10 +626,11 @@
                             else
                             {
                                 byte[] data = new byte[(int) length];
+                                DataInputStream inf = null;
 
                                 try
                                 {
-                                    DataInputStream inf = new DataInputStream( new FileInputStream(
file ) );
+                                    inf = new DataInputStream( new FileInputStream( file
) );
                                     inf.read( data );
 
                                     return data;
@@ -646,7 +648,21 @@
                                     log.error( "File {} error reading", fileName );
                                     throw new NamingException( "Bad URL, file can't be read"
);
                                 }
-
+                                finally
+                                {
+                                    if ( inf != null )
+                                    {
+                                        try
+                                        {
+                                            inf.close();
+                                        }
+                                        catch ( IOException ioe )
+                                        {
+                                            log.error( "Error while closing the stream :
{}", ioe.getMessage() );
+                                            // Just do nothing ...
+                                        }
+                                    }
+                                }
                             }
                         }
                     }
@@ -1549,7 +1565,7 @@
 
             if ( log.isDebugEnabled() )
             {
-                log.debug( "Parsed {} entries.", ( entries == null ? new Integer( 0 ) : new
Integer( entries.size() ) ) );
+                log.debug( "Parsed {} entries.", ( entries == null ? Integer.valueOf( 0 )
: Integer.valueOf( entries.size() ) ) );
             }
 
             return entries;
@@ -1570,7 +1586,7 @@
      * 
      * @return the next LDIF as a String.
      */
-    public Object next()
+    public Object next() throws NoSuchElementException
     {
         try
         {



Mime
View raw message