Index: src/java/org/apache/lucene/store/NIOFSDirectory.java =================================================================== --- src/java/org/apache/lucene/store/NIOFSDirectory.java (revision 713425) +++ src/java/org/apache/lucene/store/NIOFSDirectory.java (working copy) @@ -43,6 +43,43 @@ public class NIOFSDirectory extends FSDirectory { + /** Returns the directory instance for the named location. + * @param path the path to the directory. + * @return the FSDirectory for the named file. */ + public static FSDirectory getDirectory(String path) + throws IOException { + return getDirectory(new File(path), null); + } + + /** Returns the directory instance for the named location. + * @param path the path to the directory. + * @param lockFactory instance of {@link LockFactory} providing the + * locking implementation. + * @return the FSDirectory for the named file. */ + public static FSDirectory getDirectory(String path, LockFactory lockFactory) + throws IOException { + return getDirectory(new File(path), lockFactory); + } + + /** Returns the directory instance for the named location. + * @param file the path to the directory. + * @return the FSDirectory for the named file. */ + public static FSDirectory getDirectory(File file) + throws IOException { + return getDirectory(file, null); + } + + /** Returns the directory instance for the named location. + * @param file the path to the directory. + * @param lockFactory instance of {@link LockFactory} providing the + * locking implementation. + * @return the FSDirectory for the named file. */ + public static FSDirectory getDirectory(File file, LockFactory lockFactory) + throws IOException + { + return getDirectory(NIOFSDirectory.class, file, lockFactory); + } + // Inherit javadoc public IndexInput openInput(String name, int bufferSize) throws IOException { ensureOpen(); Index: src/java/org/apache/lucene/store/MMapDirectory.java =================================================================== --- src/java/org/apache/lucene/store/MMapDirectory.java (revision 713425) +++ src/java/org/apache/lucene/store/MMapDirectory.java (working copy) @@ -33,6 +33,44 @@ */ public class MMapDirectory extends FSDirectory { + /** Returns the directory instance for the named location. + * @param path the path to the directory. + * @return the FSDirectory for the named file. */ + public static FSDirectory getDirectory(String path) + throws IOException { + return getDirectory(new File(path), null); + } + + /** Returns the directory instance for the named location. + * @param path the path to the directory. + * @param lockFactory instance of {@link LockFactory} providing the + * locking implementation. + * @return the FSDirectory for the named file. */ + public static FSDirectory getDirectory(String path, LockFactory lockFactory) + throws IOException { + return getDirectory(new File(path), lockFactory); + } + + /** Returns the directory instance for the named location. + * @param file the path to the directory. + * @return the FSDirectory for the named file. */ + public static FSDirectory getDirectory(File file) + throws IOException { + return getDirectory(file, null); + } + + /** Returns the directory instance for the named location. + * @param file the path to the directory. + * @param lockFactory instance of {@link LockFactory} providing the + * locking implementation. + * @return the FSDirectory for the named file. */ + public static FSDirectory getDirectory(File file, LockFactory lockFactory) + throws IOException + { + return getDirectory(MMapDirectory.class, file, lockFactory); + } + + private static class MMapIndexInput extends IndexInput { private ByteBuffer buffer; Index: src/java/org/apache/lucene/store/FSDirectory.java =================================================================== --- src/java/org/apache/lucene/store/FSDirectory.java (revision 713425) +++ src/java/org/apache/lucene/store/FSDirectory.java (working copy) @@ -157,7 +157,8 @@ return getDirectory(file, null); } - /** Returns the directory instance for the named location. + + /** Returns the directory instance for the named location. * @param file the path to the directory. * @param lockFactory instance of {@link LockFactory} providing the * locking implementation. @@ -165,6 +166,17 @@ public static FSDirectory getDirectory(File file, LockFactory lockFactory) throws IOException { + return getDirectory(IMPL, file, lockFactory); + } + + /** Returns the directory instance for the named location. + * @param file the path to the directory. + * @param lockFactory instance of {@link LockFactory} providing the + * locking implementation. + * @return the FSDirectory for the named file. */ + protected static FSDirectory getDirectory(Class directoryImpl, File file, LockFactory lockFactory) + throws IOException + { file = new File(file.getCanonicalPath()); if (file.exists() && !file.isDirectory()) @@ -179,7 +191,7 @@ dir = (FSDirectory)DIRECTORIES.get(file); if (dir == null) { try { - dir = (FSDirectory)IMPL.newInstance(); + dir = (FSDirectory)directoryImpl.newInstance(); } catch (Exception e) { throw new RuntimeException("cannot load FSDirectory class: " + e.toString(), e); }