Index: lucene/CHANGES.txt =================================================================== --- lucene/CHANGES.txt (revision 1037654) +++ lucene/CHANGES.txt (working copy) @@ -221,6 +221,9 @@ * LUCENE-2699: Update StandardTokenizer and UAX29Tokenizer to Unicode 6.0.0. (Steven Rowe) +* LUCENE-2778: RAMDirectory now exposes newRAMFile() which allows to override + and return a different RAMFile implementation. (Shai Erera) + Bug fixes * LUCENE-2216: OpenBitSet.hashCode returned different hash codes for Index: lucene/src/java/org/apache/lucene/store/RAMDirectory.java =================================================================== --- lucene/src/java/org/apache/lucene/store/RAMDirectory.java (revision 1037654) +++ lucene/src/java/org/apache/lucene/store/RAMDirectory.java (working copy) @@ -36,8 +36,8 @@ private static final long serialVersionUID = 1l; - HashMap fileMap = new HashMap(); - final AtomicLong sizeInBytes = new AtomicLong(); + protected HashMap fileMap = new HashMap(); + protected final AtomicLong sizeInBytes = new AtomicLong(); // ***** // Lock acquisition sequence: RAMDirectory, then RAMFile @@ -174,9 +174,8 @@ @Override public synchronized void deleteFile(String name) throws IOException { ensureOpen(); - RAMFile file = fileMap.get(name); + RAMFile file = fileMap.remove(name); if (file!=null) { - fileMap.remove(name); file.directory = null; sizeInBytes.addAndGet(-file.sizeInBytes); } else @@ -187,7 +186,7 @@ @Override public IndexOutput createOutput(String name) throws IOException { ensureOpen(); - RAMFile file = new RAMFile(this); + RAMFile file = newRAMFile(); synchronized (this) { RAMFile existing = fileMap.get(name); if (existing!=null) { @@ -199,6 +198,15 @@ return new RAMOutputStream(file); } + /** + * Returns a new {@link RAMFile} for storing data. This method can be + * overridden to return different {@link RAMFile} impls, that e.g. override + * {@link RAMFile#newBuffer(int)}. + */ + protected RAMFile newRAMFile() { + return new RAMFile(this); + } + /** Returns a stream reading an existing file. */ @Override public IndexInput openInput(String name) throws IOException {