@@ -0,0 +1,2567 @@
+package org.apache.lucene.store;%0A%0A/**%0A * Copyright 2004 The Apache Software Foundation%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Aimport java.io.IOException;%0Aimport java.io.File;%0Aimport java.io.RandomAccessFile;%0Aimport java.nio.ByteBuffer;%0Aimport java.nio.channels.FileChannel;%0Aimport java.nio.channels.FileChannel.MapMode;%0A%0A/** File-based %7B@link Directory%7D implementation that uses mmap for input.%0A *%0A * %3Cp%3ETo use this, invoke Java with the System property%0A * org.apache.lucene.FSDirectory.class set to%0A * org.apache.lucene.store.MMapDirectory.  This will cause %7B@link%0A * FSDirectory#getDirectory(File,boolean)%7D to return instances of this class.%0A *%0A * @author Doug Cutting%0A */%0Apublic class MMapDirectory extends FSDirectory %7B%0A%0A  private class MMapIndexInput extends IndexInput %7B%0A%0A    private ByteBuffer buffer;%0A    private RandomAccessFile file;%0A    private long length;%0A    private boolean isClone;%0A%0A    public MMapIndexInput(String path) throws IOException %7B%0A      this.file = new RandomAccessFile(path, %22r%22);%0A      this.length = file.length();%0A      this.buffer = file.getChannel().map(MapMode.READ_ONLY, 0, length);%0A    %7D%0A%0A    public byte readByte() throws IOException %7B%0A      return buffer.get();%0A    %7D%0A%0A    public void readBytes(byte%5B%5D b, int offset, int len)%0A      throws IOException %7B%0A      buffer.get(b, offset, len);%0A    %7D%0A%0A    public long getFilePointer() %7B%0A      return buffer.position();%0A    %7D%0A%0A    public void seek(long pos) throws IOException %7B%0A      buffer.position((int)pos);%0A    %7D%0A%0A    public long length() %7B%0A      return length;%0A    %7D%0A%0A    public Object clone() %7B%0A      MMapIndexInput clone = (MMapIndexInput)super.clone();%0A      clone.isClone = true;%0A      clone.buffer = buffer.duplicate();%0A      return clone;%0A    %7D%0A%0A    public void close() throws IOException %7B%0A      if (!isClone)%0A        file.close();%0A    %7D%0A  %7D%0A%0A  private MMapDirectory() %7B%7D                      // no public ctor%0A%0A  public IndexInput openInput(String name) throws IOException %7B%0A    return new MMapIndexInput(new File(getFile(), name).getPath());%0A  %7D%0A%7D%0A%0A

Add an nio mmap based Directory implementation.