TermInfosReader(Directory dir, String seg, FieldInfos fis, int readBufferSize, int indexDivisor)
       throws CorruptIndexException, IOException {
    boolean success = false;

    if (indexDivisor < 1 && indexDivisor != -1) {
      throw new IllegalArgumentException("indexDivisor must be -1 (don't load terms index) or greater than 0: got " + indexDivisor);
    }

    try {
        directory = dir;
        segment = seg;
        fieldInfos = fis;

        origEnum = new SegmentTermEnum(directory.openInput(segment + "." + IndexFileNames.TERMS_EXTENSION,
            readBufferSize), fieldInfos, false);
        size = origEnum.size;
        
        //read in bloom filter.... here if it exists...
        BloomFilter filter = TermInfosCache.getFromCache(getRealDir(directory), segment);
        if (filter == null && bloomFilterEnabled) {
	        if (directory.fileExists(segment + "." + IndexFileNames.BLOOM_FILTER_EXTENSION)) {
	            IndexInput openInput = directory.openInput(segment + "." + IndexFileNames.BLOOM_FILTER_EXTENSION);
	            if (openInput.readLong() != -1L) {
	                openInput.seek(0);
    	        	bloomFilter = new BloomFilter();
    				bloomFilter.read(openInput);
    				openInput.close();
	            }
	        }
        }

        if (indexDivisor != -1) {
          // Load terms index
          totalIndexInterval = origEnum.indexInterval * indexDivisor;
          final SegmentTermEnum indexEnum = new SegmentTermEnum(directory.openInput(segment + "." + IndexFileNames.TERMS_INDEX_EXTENSION,
                                                                                    readBufferSize), fieldInfos, true);
          try {
              index = new TermInfosReaderIndex(directory,segment);
              index.build(indexEnum, indexDivisor, (int) dir.fileLength(segment + "." + IndexFileNames.TERMS_INDEX_EXTENSION));
              indexLength = index.length();
          } finally {
            indexEnum.close();
          }
        } else {
          // Do not load terms index:
          totalIndexInterval = -1;
          index = null;
        }
        success = true;
      } finally {
      // With lock-less commits, it's entirely possible (and
      // fine) to hit a FileNotFound exception above. In
      // this case, we want to explicitly close any subset
      // of things that were opened so that we don't have to
      // wait for a GC to do so.
      if (!success) {
        close();
      }
    }
  }