### Eclipse Workspace Patch 1.0
#P lucene
Index: lucene/src/java/org/apache/lucene/index/CompoundFileReader.java
===================================================================
--- lucene/src/java/org/apache/lucene/index/CompoundFileReader.java	(revision 1128825)
+++ lucene/src/java/org/apache/lucene/index/CompoundFileReader.java	(working copy)
@@ -37,7 +37,7 @@
  */
 public class CompoundFileReader extends Directory {
 
-    private int readBufferSize;
+    private IOContext context;
 
     private static final class FileEntry {
         long offset;
@@ -52,20 +52,15 @@
     private IndexInput stream;
     private HashMap<String,FileEntry> entries = new HashMap<String,FileEntry>();
 
-
-  public CompoundFileReader(Directory dir, String name) throws IOException {
-    this(dir, name, BufferedIndexInput.BUFFER_SIZE);
-  }
-
-  public CompoundFileReader(Directory dir, String name, int readBufferSize) throws IOException {
+  public CompoundFileReader(Directory dir, String name, IOContext context) throws IOException {
         directory = dir;
         fileName = name;
-        this.readBufferSize = readBufferSize;
+        this.context = context;
 
         boolean success = false;
 
         try {
-            stream = dir.openInput(name, readBufferSize);
+            stream = dir.openInput(name, context);
 
             // read the first VInt. If it is negative, it's the version number
             // otherwise it's the count (pre-3.1 indexes)
@@ -143,17 +138,9 @@
     }
 
     @Override
-    public synchronized IndexInput openInput(String id)
+    public synchronized IndexInput openInput(String id, IOContext context)
     throws IOException
     {
-      // Default to readBufferSize passed in when we were opened
-      return openInput(id, readBufferSize);
-    }
-
-    @Override
-    public synchronized IndexInput openInput(String id, int readBufferSize)
-    throws IOException
-    {
         if (stream == null)
             throw new IOException("Stream closed");
         
@@ -162,7 +149,7 @@
         if (entry == null)
           throw new IOException("No sub-file with id " + id + " found (files: " + entries.keySet() + ")");
 
-        return new CSIndexInput(stream, entry.offset, entry.length, readBufferSize);
+        return new CSIndexInput(stream, entry.offset, entry.length, context);        
     }
 
     /** Returns an array of strings, one for each file in the directory. */
@@ -217,7 +204,7 @@
     /** Not implemented
      * @throws UnsupportedOperationException */
     @Override
-    public IndexOutput createOutput(String name)
+    public IndexOutput createOutput(String name, IOContext context)
     {
         throw new UnsupportedOperationException();
     }
Index: lucene/src/java/org/apache/lucene/store/Directory.java
===================================================================
--- lucene/src/java/org/apache/lucene/store/Directory.java	(revision 1128825)
+++ lucene/src/java/org/apache/lucene/store/Directory.java	(working copy)
@@ -22,6 +22,7 @@
 import java.io.Closeable;
 import java.util.Collection; // for javadocs
 
+import org.apache.lucene.index.IOContext;
 import org.apache.lucene.util.IOUtils;
 
 /** A Directory is a flat list of files.  Files may be written once, when they
@@ -87,7 +88,7 @@
 
   /** Creates a new, empty file in the directory with the given name.
       Returns a stream writing this file. */
-  public abstract IndexOutput createOutput(String name)
+  public abstract IndexOutput createOutput(String name, IOContext context)
        throws IOException;
 
   /**
@@ -103,10 +104,6 @@
    */
   public abstract void sync(Collection<String> names) throws IOException;
 
-  /** Returns a stream reading an existing file. */
-  public abstract IndexInput openInput(String name)
-    throws IOException;
-
   /** Returns a stream reading an existing file, with the
    * specified read buffer size.  The particular Directory
    * implementation may ignore the buffer size.  Currently
@@ -114,8 +111,8 @@
    * parameter are {@link FSDirectory} and {@link
    * org.apache.lucene.index.CompoundFileReader}.
   */
-  public IndexInput openInput(String name, int bufferSize) throws IOException {
-    return openInput(name);
+  public IndexInput openInput(String name, IOContext context) throws IOException {
+    return openInput(name, context);
   }
 
   /** Construct a {@link Lock}.
@@ -199,9 +196,9 @@
    * <b>NOTE:</b> this method does not check whether <i>dest<i> exist and will
    * overwrite it if it does.
    */
-  public void copy(Directory to, String src, String dest) throws IOException {
-    IndexOutput os = to.createOutput(dest);
-    IndexInput is = openInput(src);
+  public void copy(Directory to, String src, String dest, IOContext context) throws IOException {
+    IndexOutput os = to.createOutput(dest, context);
+    IndexInput is = openInput(src, context);
     IOException priorException = null;
     try {
       is.copyBytes(os, is.length());
Index: lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java
===================================================================
--- lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java	(revision 1128825)
+++ lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java	(working copy)
@@ -21,6 +21,8 @@
 import java.io.IOException;
 import java.io.RandomAccessFile;
 
+import org.apache.lucene.index.IOContext;
+
 /** A straightforward implementation of {@link FSDirectory}
  *  using java.io.RandomAccessFile.  However, this class has
  *  poor concurrent performance (multiple threads will
@@ -51,9 +53,9 @@
 
   /** Creates an IndexInput for the file with the given name. */
   @Override
-  public IndexInput openInput(String name, int bufferSize) throws IOException {
+  public IndexInput openInput(String name, IOContext context) throws IOException {
     ensureOpen();
-    return new SimpleFSIndexInput(new File(directory, name), bufferSize, getReadChunkSize());
+    return new SimpleFSIndexInput(new File(directory, name), context, getReadChunkSize());
   }
 
   protected static class SimpleFSIndexInput extends BufferedIndexInput {
@@ -85,8 +87,8 @@
     //  LUCENE-1566 - maximum read length on a 32bit JVM to prevent incorrect OOM 
     protected final int chunkSize;
     
-    public SimpleFSIndexInput(File path, int bufferSize, int chunkSize) throws IOException {
-      super(bufferSize);
+    public SimpleFSIndexInput(File path, IOContext context, int chunkSize) throws IOException {
+//      super(bufferSize);
       file = new Descriptor(path, "r");
       this.chunkSize = chunkSize;
     }
Index: lucene/src/java/org/apache/lucene/store/MMapDirectory.java
===================================================================
--- lucene/src/java/org/apache/lucene/store/MMapDirectory.java	(revision 1128825)
+++ lucene/src/java/org/apache/lucene/store/MMapDirectory.java	(working copy)
@@ -31,6 +31,7 @@
 import java.security.PrivilegedActionException;
 import java.lang.reflect.Method;
 
+import org.apache.lucene.index.IOContext;
 import org.apache.lucene.util.Constants;
 
 /** File-based {@link Directory} implementation that uses
@@ -201,7 +202,7 @@
 
   /** Creates an IndexInput for the file with the given name. */
   @Override
-  public IndexInput openInput(String name, int bufferSize) throws IOException {
+  public IndexInput openInput(String name, IOContext context) throws IOException {
     ensureOpen();
     File f = new File(getDirectory(), name);
     RandomAccessFile raf = new RandomAccessFile(f, "r");
@@ -477,4 +478,5 @@
       }
     }
   }
+
 }
Index: lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java
===================================================================
--- lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java	(revision 1128825)
+++ lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java	(working copy)
@@ -24,6 +24,7 @@
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.lucene.index.ConcurrentMergeScheduler;
+import org.apache.lucene.index.IOContext;
 import org.apache.lucene.index.IndexFileNames;
 import org.apache.lucene.index.IndexWriter;       // javadocs
 import org.apache.lucene.index.MergePolicy;
@@ -158,7 +159,7 @@
   }
 
   @Override
-  public IndexOutput createOutput(String name) throws IOException {
+  public IndexOutput createOutput(String name, IOContext context) throws IOException {
     if (VERBOSE) {
       System.out.println("nrtdir.createOutput name=" + name);
     }
@@ -166,9 +167,9 @@
       if (VERBOSE) {
         System.out.println("  to cache");
       }
-      return cache.createOutput(name);
+      return cache.createOutput(name, context);
     } else {
-      return delegate.createOutput(name);
+      return delegate.createOutput(name, context);
     }
   }
 
@@ -184,7 +185,7 @@
   }
 
   @Override
-  public synchronized IndexInput openInput(String name) throws IOException {
+  public synchronized IndexInput openInput(String name, IOContext context) throws IOException {
     if (VERBOSE) {
       System.out.println("nrtdir.openInput name=" + name);
     }
@@ -192,22 +193,13 @@
       if (VERBOSE) {
         System.out.println("  from cache");
       }
-      return cache.openInput(name);
+      return cache.openInput(name, context);
     } else {
-      return delegate.openInput(name);
+      return delegate.openInput(name, context);
     }
   }
-
+  
   @Override
-  public synchronized IndexInput openInput(String name, int bufferSize) throws IOException {
-    if (cache.fileExists(name)) {
-      return cache.openInput(name, bufferSize);
-    } else {
-      return delegate.openInput(name, bufferSize);
-    }
-  }
-
-  @Override
   public Lock makeLock(String name) {
     return delegate.makeLock(name);
   }
@@ -252,12 +244,12 @@
     return !name.equals(IndexFileNames.SEGMENTS_GEN) && (merge == null || merge.estimatedMergeBytes <= maxMergeSizeBytes) && cache.sizeInBytes() <= maxCachedBytes;
   }
 
-  private void unCache(String fileName) throws IOException {
+  private void unCache(String fileName, IOContext context) throws IOException {
     final IndexOutput out;
     synchronized(this) {
       if (!delegate.fileExists(fileName)) {
         assert cache.fileExists(fileName);
-        out = delegate.createOutput(fileName);
+        out = delegate.createOutput(fileName, context);
       } else {
         out = null;
       }
@@ -266,7 +258,7 @@
     if (out != null) {
       IndexInput in = null;
       try {
-        in = cache.openInput(fileName);
+        in = cache.openInput(fileName, context);
         in.copyBytes(out, in.length());
       } finally {
         IOUtils.closeSafely(in, out);
Index: lucene/src/java/org/apache/lucene/store/RAMDirectory.java
===================================================================
--- lucene/src/java/org/apache/lucene/store/RAMDirectory.java	(revision 1128825)
+++ lucene/src/java/org/apache/lucene/store/RAMDirectory.java	(working copy)
@@ -27,6 +27,8 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.apache.lucene.index.IOContext;
+
 /**
  * A memory-resident {@link Directory} implementation.  Locking
  * implementation is by default the {@link SingleInstanceLockFactory}
@@ -38,7 +40,7 @@
   
   // *****
   // Lock acquisition sequence:  RAMDirectory, then RAMFile
-  // *****
+  // ***** 
 
   /** Constructs an empty {@link Directory}. */
   public RAMDirectory() {
@@ -65,14 +67,14 @@
    * @param dir a <code>Directory</code> value
    * @exception IOException if an error occurs
    */
-  public RAMDirectory(Directory dir) throws IOException {
-    this(dir, false);
+  public RAMDirectory(Directory dir,IOContext context) throws IOException {
+    this(dir, false,context);    
   }
   
-  private RAMDirectory(Directory dir, boolean closeDir) throws IOException {
+  private RAMDirectory(Directory dir, boolean closeDir,IOContext context) throws IOException {
     this();
     for (String file : dir.listAll()) {
-      dir.copy(this, file, file);
+      dir.copy(this, file, file,context);
     }
     if (closeDir) {
       dir.close();
@@ -149,7 +151,7 @@
 
   /** Creates a new, empty file in the directory with the given name. Returns a stream writing this file. */
   @Override
-  public IndexOutput createOutput(String name) throws IOException {
+  public IndexOutput createOutput(String name, IOContext context) throws IOException {
     ensureOpen();
     RAMFile file = newRAMFile();
     RAMFile existing = fileMap.remove(name);
@@ -176,7 +178,7 @@
 
   /** Returns a stream reading an existing file. */
   @Override
-  public IndexInput openInput(String name) throws IOException {
+  public IndexInput openInput(String name, IOContext context) throws IOException {
     ensureOpen();
     RAMFile file = fileMap.get(name);
     if (file == null) {
Index: lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java
===================================================================
--- lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java	(revision 1128825)
+++ lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java	(working copy)
@@ -25,6 +25,8 @@
 import java.util.Set;
 import java.util.HashSet;
 
+import org.apache.lucene.index.IOContext;
+
 /**
  * Expert: A Directory instance that switches files between
  * two other Directory instances.
@@ -125,8 +127,8 @@
   }
 
   @Override
-  public IndexOutput createOutput(String name) throws IOException {
-    return getDirectory(name).createOutput(name);
+  public IndexOutput createOutput(String name, IOContext context) throws IOException {
+    return getDirectory(name).createOutput(name, context);
   }
 
   @Override
@@ -145,7 +147,7 @@
   }
 
   @Override
-  public IndexInput openInput(String name) throws IOException {
-    return getDirectory(name).openInput(name);
+  public IndexInput openInput(String name, IOContext context) throws IOException {
+    return getDirectory(name).openInput(name, context);
   }
 }
Index: lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java
===================================================================
--- lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java	(revision 1128825)
+++ lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java	(working copy)
@@ -19,6 +19,8 @@
 
 import java.io.File;
 import java.io.IOException;
+
+import org.apache.lucene.index.IOContext;
 import org.apache.lucene.store.Directory; // javadoc
 import org.apache.lucene.store.NativeFSLockFactory; // javadoc
 
@@ -67,9 +69,9 @@
   }
 
   @Override
-  public IndexInput openInput(String name, int bufferSize) throws IOException {
+  public IndexInput openInput(String name, IOContext context) throws IOException {
     ensureOpen();
-    return new WindowsIndexInput(new File(getDirectory(), name), Math.max(bufferSize, DEFAULT_BUFFERSIZE));
+    return new WindowsIndexInput(new File(getDirectory(), name), DEFAULT_BUFFERSIZE);
   }
   
   protected static class WindowsIndexInput extends BufferedIndexInput {
Index: lucene/src/java/org/apache/lucene/index/IndexReader.java
===================================================================
--- lucene/src/java/org/apache/lucene/index/IndexReader.java	(revision 1128825)
+++ lucene/src/java/org/apache/lucene/index/IndexReader.java	(working copy)
@@ -1411,13 +1411,15 @@
 
     Directory dir = null;
     CompoundFileReader cfr = null;
+    IOContext context=null;
+    //TODO: Fill in IOContext
 
     try {
       File file = new File(filename);
       String dirname = file.getAbsoluteFile().getParent();
       filename = file.getName();
       dir = FSDirectory.open(new File(dirname));
-      cfr = new CompoundFileReader(dir, filename);
+      cfr = new CompoundFileReader(dir, filename, context);
 
       String [] files = cfr.listAll();
       ArrayUtil.mergeSort(files);   // sort the array of filename so that the output is more readable
@@ -1427,7 +1429,7 @@
 
         if (extract) {
           System.out.println("extract " + files[i] + " with " + len + " bytes to local directory...");
-          IndexInput ii = cfr.openInput(files[i]);
+          IndexInput ii = cfr.openInput(files[i], context);
 
           FileOutputStream f = new FileOutputStream(files[i]);
 
Index: lucene/src/java/org/apache/lucene/store/FSDirectory.java
===================================================================
--- lucene/src/java/org/apache/lucene/store/FSDirectory.java	(revision 1128825)
+++ lucene/src/java/org/apache/lucene/store/FSDirectory.java	(working copy)
@@ -31,6 +31,7 @@
 import java.util.Set;
 import java.util.concurrent.Future;
 
+import org.apache.lucene.index.IOContext;
 import org.apache.lucene.util.ThreadInterruptedException;
 import org.apache.lucene.util.Constants;
 
@@ -297,7 +298,7 @@
 
   /** Creates an IndexOutput for the file with the given name. */
   @Override
-  public IndexOutput createOutput(String name) throws IOException {
+  public IndexOutput createOutput(String name, IOContext context) throws IOException {
     ensureOpen();
 
     ensureCanWrite(name);
@@ -332,9 +333,9 @@
 
   // Inherit javadoc
   @Override
-  public IndexInput openInput(String name) throws IOException {
+  public IndexInput openInput(String name, IOContext context) throws IOException {
     ensureOpen();
-    return openInput(name, BufferedIndexInput.BUFFER_SIZE);
+    return openInput(name, context);
   }
 
   /**
Index: lucene/src/java/org/apache/lucene/index/IOContext.java
===================================================================
--- lucene/src/java/org/apache/lucene/index/IOContext.java	(revision 0)
+++ lucene/src/java/org/apache/lucene/index/IOContext.java	(revision 0)
@@ -0,0 +1,38 @@
+package org.apache.lucene.index;
+
+import org.apache.lucene.index.MergePolicy.OneMerge;
+
+/**
+ * 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.
+ */
+
+/**
+IOContext holds additional details on the merge/search context.
+Context is a enum which specifies the context in which the Directory is being used for.
+ */
+public class IOContext {
+  
+  public enum Context {Merge,Search};
+  
+  public final Context context;
+  public final OneMerge onemerge;
+  
+  private IOContext(Context c, OneMerge onemerge) {
+    this.context=c;
+    this.onemerge=onemerge;
+  }
+  
+}
\ No newline at end of file
Index: lucene/src/java/org/apache/lucene/index/IndexWriter.java
===================================================================
--- lucene/src/java/org/apache/lucene/index/IndexWriter.java	(revision 1128825)
+++ lucene/src/java/org/apache/lucene/index/IndexWriter.java	(working copy)
@@ -281,6 +281,8 @@
 
   // for testing
   boolean anyNonBulkMerges;
+  
+  private IOContext context;
 
   IndexReader getReader() throws IOException {
     return getReader(true);
@@ -746,7 +748,7 @@
    *           <code>OpenMode.APPEND</code> or if there is any other low-level
    *           IO error
    */
-  public IndexWriter(Directory d, IndexWriterConfig conf)
+  public IndexWriter(Directory d, IndexWriterConfig conf, IOContext ctxt)
       throws CorruptIndexException, LockObtainFailedException, IOException {
     config = (IndexWriterConfig) conf.clone();
     directory = d;
@@ -760,6 +762,7 @@
     bufferedDeletesStream = new BufferedDeletesStream(messageID);
     bufferedDeletesStream.setInfoStream(infoStream);
     poolReaders = conf.getReaderPooling();
+    context=ctxt;
 
     OpenMode mode = conf.getOpenMode();
     boolean create;
@@ -2487,7 +2490,7 @@
         cfsWriter.addFile(file, info.dir);
       } else {
         assert !directory.fileExists(newFileName): "file \"" + newFileName + "\" already exists";
-        info.dir.copy(directory, file, newFileName);
+        info.dir.copy(directory, file, newFileName, context);
       }
     }
     
@@ -2537,7 +2540,7 @@
       }
       
       assert !directory.fileExists(newFileName): "file \"" + newFileName + "\" already exists";
-      info.dir.copy(directory, file, newFileName);
+      info.dir.copy(directory, file, newFileName, context);
     }
     
     info.setDocStore(info.getDocStoreOffset(), newDsName, info.getDocStoreIsCompoundFile());
Index: lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java
===================================================================
--- lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java	(revision 1128825)
+++ lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java	(working copy)
@@ -23,6 +23,7 @@
 import java.nio.channels.ClosedChannelException; // javadoc @link
 import java.nio.channels.FileChannel;
 import java.util.concurrent.Future; // javadoc
+import org.apache.lucene.index.IOContext;
 
 /**
  * An {@link FSDirectory} implementation that uses java.nio's FileChannel's
@@ -73,9 +74,9 @@
 
   /** Creates an IndexInput for the file with the given name. */
   @Override
-  public IndexInput openInput(String name, int bufferSize) throws IOException {
+  public IndexInput openInput(String name, IOContext context) throws IOException {
     ensureOpen();
-    return new NIOFSIndexInput(new File(getDirectory(), name), bufferSize, getReadChunkSize());
+    return new NIOFSIndexInput(new File(getDirectory(), name), context, getReadChunkSize());
   }
 
   protected static class NIOFSIndexInput extends SimpleFSDirectory.SimpleFSIndexInput {
@@ -87,8 +88,8 @@
 
     final FileChannel channel;
 
-    public NIOFSIndexInput(File path, int bufferSize, int chunkSize) throws IOException {
-      super(path, bufferSize, chunkSize);
+    public NIOFSIndexInput(File path, IOContext context, int chunkSize) throws IOException {
+      super(path, context, chunkSize);
       channel = file.getChannel();
     }
 
@@ -178,4 +179,5 @@
       }
     }
   }
+
 }
Index: lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java
===================================================================
--- lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java	(revision 1128825)
+++ lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java	(working copy)
@@ -25,6 +25,7 @@
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 
+import org.apache.lucene.index.IOContext;
 import org.apache.lucene.store.Directory; // javadoc
 import org.apache.lucene.store.NativeFSLockFactory; // javadoc
 
@@ -69,13 +70,13 @@
   }
 
   @Override
-  public IndexInput openInput(String name, int bufferSize) throws IOException {
+  public IndexInput openInput(String name, IOContext context) throws IOException {
     ensureOpen();
-    return new DirectIOLinuxIndexInput(new File(getDirectory(), name), forcedBufferSize == 0 ? bufferSize : forcedBufferSize);
+    return new DirectIOLinuxIndexInput(new File(getDirectory(), name), forcedBufferSize == 0 ? BufferedIndexInput.BUFFER_SIZE : forcedBufferSize);
   }
 
   @Override
-  public IndexOutput createOutput(String name) throws IOException {
+  public IndexOutput createOutput(String name,IOContext context) throws IOException {
     ensureOpen();
     ensureCanWrite(name);
     return new DirectIOLinuxIndexOutput(new File(getDirectory(), name), forcedBufferSize == 0 ? BufferedIndexOutput.BUFFER_SIZE : forcedBufferSize);
