private void writeTerm(int fieldNumber, byte[] termBytes, int termBytesLength)
       throws IOException {

	if (!isIndex && bloomFilterEnabled) {
	  int keyBuffer = setKeyBuffer(fieldNumber,termBytes,termBytesLength);
	  if (keyBuffer > 0) {
		bloomFilter.addBytes(bloomKeyBuffer.array(), 0, keyBuffer); 
	  }
	}
    // TODO: UTF16toUTF8 could tell us this prefix
    // Compute prefix in common with last term:
    int start = 0;
    final int limit = termBytesLength < lastTermBytesLength ? termBytesLength : lastTermBytesLength;
    while(start < limit) {
      if (termBytes[start] != lastTermBytes[start])
        break;
      start++;
    }

    final int length = termBytesLength - start;
    output.writeVInt(start);                     // write shared prefix length
    output.writeVInt(length);                  // write delta length
    output.writeBytes(termBytes, start, length);  // write delta bytes
    output.writeVInt(fieldNumber); // write field num
    if (lastTermBytes.length < termBytesLength) {
      byte[] newArray = new byte[(int) (termBytesLength*1.5)];
      System.arraycopy(lastTermBytes, 0, newArray, 0, start);
      lastTermBytes = newArray;
    }
    System.arraycopy(termBytes, start, lastTermBytes, start, length);
    lastTermBytesLength = termBytesLength;
  }