private void internalReset(String term) throws IOException {
    if (indexFile != null) {
      if (index == null) {
        index =
            new ImmutableBTreeIndex.Reader<String, LongPair>(
                indexFile, new StringSerializer(), new LongPairSerializer(), false);
      }
      Generation.Entry<String, LongPair> e = index.floor(term);
      if (e == null) {
        e = index.first();
      }
      lastTermBytes = e.getKey().getBytes(Charsets.UTF_8);
      lastTermByteBuffer = ByteBuffer.wrap(lastTermBytes);
      lastTermLength = lastTermBytes.length;
      lastString = null;
      final LongPair p = e.getValue();
      refillBuffer(p.getFirst());
      lastTermOffset = p.getSecond();
      lastTermDocFreq = (int) readVLong();
      done = false;

      while (decoder
                  .decode((ByteBuffer) lastTermByteBuffer.position(0).limit(lastTermLength))
                  .toString()
                  .compareTo(term)
              < 0
          && next()) {}
      bufferNext = true;
    } else {
      lastTermLength = 0;
      lastTermOffset = 0L;
      lastTermDocFreq = 0;
      lastString = null;

      bufferLen = 0;
      bufferOffset = 0L;
      bufferPtr = 0;

      done = false;

      while (next()
          && new String(lastTermBytes, 0, lastTermLength, Charsets.UTF_8).compareTo(term) < 0) {}
      bufferNext = true;
    }
  }
 @Override
 public void close() {
   if (!closed) {
     try {
       if (index != null) {
         index.close();
       }
     } catch (IOException e) {
       log.error("error closing index", e);
     }
     try {
       file.close();
     } catch (IOException e) {
       log.error("error closing file", e);
     }
     closed = true;
   }
 }