You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by Kevin Ross <Ke...@iverticalleap.com> on 2004/10/29 20:40:05 UTC

RE: Out of memory exception when adding multiple documents from the command line - patch given

It is extremely easy with Eclipse as long as you have checked out the source
from the CVS repository.

 

1.	Check out the source files from the repository, 
2.	Make your changes
3.	Right click on the project
4.	Select Team | Create patch..
5.	Save to file system (put in a name)
6.	Make sure to select the Unified Diff format.

 

Create a bug in bugzilla, add [patch] to the subject, and attach your patch
file.

 

-Kevin

 

  _____  

From: Daniel Migowski [mailto:Mig-O@artis.uni-oldenburg.de] 
Sent: Friday, October 29, 2004 1:44 PM
To: xindice-dev@xml.apache.org
Subject: Bug: Out of memory exception when adding multiple documents from
the command line - patch given

 

Hallo xindice-dev,

 There is a bug resulting from not closing the input streams in
org.apache.xindice.tools.command.AddMultipleDocuments

Please replace the appended class (I only added the insr.close(); ).
Sorry, but I'm not capable in creating nice diff files with eclipse (Does
someone knows a tool to do that?).

greetings
Daniel Migowski

-----------------------

public class AddMultipleDocuments extends Command { 

   public boolean execute(Hashtable table) throws Exception { 

       Collection col = null; 
       try { 

           // Verify that user has supplied necessary arguments 
           if (table.get(XMLTools.COLLECTION) == null) { 
               System.out.println("ERROR : Collection and switch required");

               return false; 
           } 

           if ("".equals(table.get(XMLTools.FILE_PATH))) { 
               System.out.println("ERROR : Directory name and switch
required"); 
               return false; 
           } 

           final String local = (String) table.get(XMLTools.LOCAL); 

           // Get a Collection reference to the collection 
           String colstring = normalizeCollectionURI((String)
table.get(XMLTools.COLLECTION), 
                                                     local); 
           col = DatabaseManager.getCollection(colstring); 
           if (col == null) { 
               System.out.println("ERROR : Collection not found!"); 
               return false; 
           } 

           // Create a collection manager instance for the collection 
           // CollectionManager colman =
(CollectionManager)col.getService("CollectionManager",XMLDBAPIVERSION); 

           // Get a File object for the Directory passed in 
           File dir = new File((String) table.get(XMLTools.FILE_PATH)); 
           if (dir.isDirectory()) { 

               String[] children = new String[]{}; 
               final String ext = (String) table.get(XMLTools.EXTENSION); 

               // If the user supplied a file extension, filter on it, else
use entire contents of the directory 
               if (!ext.equals("")) { 
                   children = dir.list(new FilenameFilter() { 
                       public boolean accept(File none, String name) { 
                           return name.endsWith("." + ext); 
                       } 
                   }); 
               } else if (ext.equals("")) { 
                   children = dir.list(); 
               } 

               System.out.println("Reading files from: " + dir.getName()); 

               // Loop over documents, adding to db 
               for (int i = 0; i < children.length; i++) { 

                   File files = new File(dir, children[i]); 
                   if (files.isFile()) { 
                       FileInputStream insr = new FileInputStream(files); 
                       byte[] fileBuffer = new byte[(int) files.length()]; 
                       insr.read(fileBuffer); 

                       try { 

                           // Use the functionality already provided in
Command.AddDocument to add this document 
                           Command cmd = (Command)
Class.forName("org.apache.xindice.tools.command.AddDocument").newInstance();

                           Hashtable localtable = new Hashtable(); 
                           String filepath = dir.getPath() + "/" +
files.getName(); 

                           // Populate hashtable to pass to AddDocument
class 
                           localtable.put(XMLTools.COLLECTION,
table.get(XMLTools.COLLECTION)); 
                           localtable.put(XMLTools.NAME_OF,
files.getName()); 
                           localtable.put(XMLTools.FILE_PATH, filepath); 
                           if (local != null) { 
                               localtable.put(XMLTools.LOCAL, local); 
                           } 

                           // Execute the class! 
                           cmd.execute(localtable); 

                           insr.close(); 

                       } catch (Exception e) { 
                           System.out.println("Error Adding File: " +
files.getName()); 
                           //System.out.println(e); 
                           continue; 
                       } 
                   } else 
                       continue; 
               } // for loop 
           } 

       } finally { 
           // Release all resources 
           if (col != null) { 
               col.close(); 
           } 
       } 

       return true; 
   } 
}