Index: lucene/src/java/org/apache/lucene/index/IndexUpgrader.java
===================================================================
--- lucene/src/java/org/apache/lucene/index/IndexUpgrader.java	(revision 1205025)
+++ lucene/src/java/org/apache/lucene/index/IndexUpgrader.java	(working copy)
@@ -17,16 +17,16 @@
  * limitations under the License.
  */
 
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
-import org.apache.lucene.util.Constants;
-import org.apache.lucene.util.Version;
-
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.util.Collection;
 
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.CommandLineUtils;
+import org.apache.lucene.util.Constants;
+import org.apache.lucene.util.Version;
+
 /**
   * This is an easy-to-use tool that upgrades all segments of an index from previous Lucene versions
   * to the current segment file format. It can be used from command line:
@@ -65,24 +65,38 @@
   @SuppressWarnings("deprecation")
   public static void main(String[] args) throws IOException {
     String dir = null;
+    String dirImpl = null;
     boolean deletePriorCommits = false;
     PrintStream out = null;
-    for (String arg : args) {
+    int j = 0;
+    while (j < args.length) {
+      String arg = args[j];
       if ("-delete-prior-commits".equals(arg)) {
         deletePriorCommits = true;
       } else if ("-verbose".equals(arg)) {
         out = System.out;
+      } else if (CommandLineUtils.DIR_IMPL_OPTION.equals(arg)) {
+        if (j == args.length - 1) {
+          System.out.println("ERROR: missing value for "
+              + CommandLineUtils.DIR_IMPL_OPTION + " option");
+          System.exit(1);
+        }
+        j++;
+        dirImpl = args[j];
       } else if (dir == null) {
         dir = arg;
       } else {
         printUsage();
       }
+      j++;
     }
     if (dir == null) {
       printUsage();
     }
     
-    new IndexUpgrader(FSDirectory.open(new File(dir)), Version.LUCENE_CURRENT, out, deletePriorCommits).upgrade();
+    Directory directory = CommandLineUtils.openDirectory(new File(dir), dirImpl);
+    new IndexUpgrader(directory, Version.LUCENE_CURRENT, out, deletePriorCommits).upgrade();    
+    
   }
   
   private final Directory dir;
Index: lucene/src/java/org/apache/lucene/index/CheckIndex.java
===================================================================
--- lucene/src/java/org/apache/lucene/index/CheckIndex.java	(revision 1205025)
+++ lucene/src/java/org/apache/lucene/index/CheckIndex.java	(working copy)
@@ -17,26 +17,25 @@
  * limitations under the License.
  */
 
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.lucene.document.AbstractField;
+import org.apache.lucene.document.Document;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.util.CommandLineUtils;
 import org.apache.lucene.util.StringHelper;
-import org.apache.lucene.document.AbstractField;  // for javadocs
-import org.apache.lucene.document.Document;
 
-import java.text.NumberFormat;
-import java.io.PrintStream;
-import java.io.IOException;
-import java.io.File;
-import java.util.Collection;
-
-import java.util.Comparator;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
-
 /**
  * Basic tool and API to check the health of an index and
  * write a new segments file that removes reference to
@@ -934,26 +933,35 @@
     boolean doFix = false;
     List<String> onlySegments = new ArrayList<String>();
     String indexPath = null;
+    String dirImpl = null;
     int i = 0;
-    while(i < args.length) {
-      if (args[i].equals("-fix")) {
+    while (i < args.length) {
+      String arg = args[i];
+      if ("-fix".equals(arg)) {
         doFix = true;
-        i++;
       } else if (args[i].equals("-segment")) {
-        if (i == args.length-1) {
+        if (i == args.length - 1) {
           System.out.println("ERROR: missing name for -segment option");
           System.exit(1);
         }
-        onlySegments.add(args[i+1]);
-        i += 2;
+        i++;
+        onlySegments.add(args[i]);
+      } else if (CommandLineUtils.DIR_IMPL_OPTION.equals(arg)) {
+        if (i == args.length - 1) {
+          System.out.println("ERROR: missing value for "
+              + CommandLineUtils.DIR_IMPL_OPTION + " option");
+          System.exit(1);
+        }
+        i++;
+        dirImpl = args[i];
       } else {
         if (indexPath != null) {
           System.out.println("ERROR: unexpected extra argument '" + args[i] + "'");
           System.exit(1);
         }
         indexPath = args[i];
-        i++;
       }
+      i++;
     }
 
     if (indexPath == null) {
@@ -994,7 +1002,7 @@
     System.out.println("\nOpening index @ " + indexPath + "\n");
     Directory dir = null;
     try {
-      dir = FSDirectory.open(new File(indexPath));
+      dir = CommandLineUtils.openDirectory(new File(indexPath), dirImpl);
     } catch (Throwable t) {
       System.out.println("ERROR: could not open directory \"" + indexPath + "\"; exiting");
       t.printStackTrace(System.out);
@@ -1028,7 +1036,7 @@
     System.out.println("");
 
     final int exitCode;
-    if (result.clean == true)
+    if (result.clean)
       exitCode = 0;
     else
       exitCode = 1;
Index: lucene/src/java/org/apache/lucene/index/IndexReader.java
===================================================================
--- lucene/src/java/org/apache/lucene/index/IndexReader.java	(revision 1205025)
+++ lucene/src/java/org/apache/lucene/index/IndexReader.java	(working copy)
@@ -27,11 +27,14 @@
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.FieldSelector;
-import org.apache.lucene.search.FieldCache; // javadocs
+import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.search.Similarity;
-import org.apache.lucene.store.*;
+import org.apache.lucene.store.AlreadyClosedException;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.LockObtainFailedException;
 import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.ReaderUtil;         // for javadocs
+import org.apache.lucene.util.CommandLineUtils;
 import org.apache.lucene.util.VirtualMethod;
 
 /** IndexReader is an abstract class, providing an interface for accessing an
@@ -1516,13 +1519,24 @@
   public static void main(String [] args) {
     String filename = null;
     boolean extract = false;
-
-    for (int i = 0; i < args.length; ++i) {
-      if (args[i].equals("-extract")) {
+    String dirImpl = null;
+    int j = 0;
+    while (j < args.length) {
+      String arg = args[j];
+      if ("-extract".equals(arg)) {
         extract = true;
+      } else if (CommandLineUtils.DIR_IMPL_OPTION.equals(arg)) {
+        if (j == args.length - 1) {
+          System.out.println("ERROR: missing value for "
+              + CommandLineUtils.DIR_IMPL_OPTION + " option");
+          System.exit(1);
+        }
+        j++;
+        dirImpl = args[j];
       } else if (filename == null) {
-        filename = args[i];
+        filename = args[j];
       }
+      j++;
     }
 
     if (filename == null) {
@@ -1537,7 +1551,7 @@
       File file = new File(filename);
       String dirname = file.getAbsoluteFile().getParent();
       filename = file.getName();
-      dir = FSDirectory.open(new File(dirname));
+      dir = CommandLineUtils.openDirectory(new File(dirname), dirImpl);
       cfr = new CompoundFileReader(dir, filename);
 
       String [] files = cfr.listAll();
Index: lucene/src/java/org/apache/lucene/util/CommandLineUtils.java
===================================================================
--- lucene/src/java/org/apache/lucene/util/CommandLineUtils.java	(revision 0)
+++ lucene/src/java/org/apache/lucene/util/CommandLineUtils.java	(revision 0)
@@ -0,0 +1,69 @@
+package org.apache.lucene.util;
+
+/**
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.MMapDirectory;
+import org.apache.lucene.store.NIOFSDirectory;
+import org.apache.lucene.store.SimpleFSDirectory;
+
+/**
+ * Utility class containing common methods used by Lucene command line tools 
+ */
+public final class CommandLineUtils {
+  
+  public static final String DIR_IMPL_OPTION = "-dir-impl";
+  
+  private static final String MMAP = "MMAP";
+  private static final String NIO = "NIO";
+  private static final String SIMPLE = "SIMPLE";
+  
+  private CommandLineUtils() {
+    
+  }
+  
+  /**
+   * Returns a specific Lucene directory instance starting from a string
+   * argument received from command line
+   * 
+   * @param file
+   *          the path of the directory
+   * @param option
+   *          the string option which contains the specific instance of
+   *          Directory
+   * @return the directory instance
+   * @throws IOException
+   */
+  public static Directory openDirectory(File file, String option)
+      throws IOException {
+    if (MMAP.equalsIgnoreCase(option)) {
+      return new MMapDirectory(file);
+    }
+    if (NIO.equalsIgnoreCase(option)) {
+      return new NIOFSDirectory(file);
+    }
+    if (SIMPLE.equalsIgnoreCase(option)) {
+      return new SimpleFSDirectory(file);
+    }
+    return FSDirectory.open(file);
+  }
+}
