FileDocCategorySizeDatePackage
MockRAMInputStream.javaAPI DocApache Lucene 2.2.02368Sat Jun 16 22:20:24 BST 2007org.apache.lucene.store

MockRAMInputStream

public class MockRAMInputStream extends RAMInputStream
Used by MockRAMDirectory to create an input stream that keeps track of when it's been closed.

Fields Summary
private MockRAMDirectory
dir
private String
name
private boolean
isClone
Constructors Summary
public MockRAMInputStream(MockRAMDirectory dir, String name, RAMFile f)
Construct an empty output buffer.

    super(f);
    this.name = name;
    this.dir = dir;
  
Methods Summary
public java.lang.Objectclone()

    MockRAMInputStream clone = (MockRAMInputStream) super.clone();
    clone.isClone = true;
    // Pending resolution on LUCENE-686 we may want to
    // uncomment this code so that we also track that all
    // clones get closed:
    /*
    synchronized(dir.openFiles) {
      if (dir.openFiles.containsKey(name)) {
        Integer v = (Integer) dir.openFiles.get(name);
        v = new Integer(v.intValue()+1);
        dir.openFiles.put(name, v);
      } else {
        throw new RuntimeException("BUG: cloned file was not open?");
      }
    }
    */
    return clone;
  
public voidclose()

    super.close();
    // Pending resolution on LUCENE-686 we may want to
    // remove the conditional check so we also track that
    // all clones get closed:
    if (!isClone) {
      synchronized(dir.openFiles) {
        Integer v = (Integer) dir.openFiles.get(name);
        if (v.intValue() == 1) {
          dir.openFiles.remove(name);
        } else {
          v = new Integer(v.intValue()-1);
          dir.openFiles.put(name, v);
        }
      }
    }