public void build(SegmentTermEnum indexEnum, int indexDivisor, int tiiFileLength) throws IOException {
		if (instantOn.load(this,directory,segment)) {
			return;
		}
		int indexSize = 1 + ((int) indexEnum.size - 1) / indexDivisor;
		indexToTerms = new int[indexSize];
		// this is only an inital size, it will be GCed once the build is complete
		int initialSize = (int) (tiiFileLength * 1.5);
		ByteArrayOutputStream baos = new ByteArrayOutputStream(initialSize);
		CustomDataOutputStream outputStream = new CustomDataOutputStream(baos);
		String currentField = null;
		List<String> fieldStrs = new ArrayList<String>();
		int fieldCounter = -1;
		for (int i = 0; indexEnum.next(); i++) {
			Term term = indexEnum.term();
			if (currentField != term.field) {
				currentField = term.field;
				fieldStrs.add(currentField);
				fieldCounter++;
			}
			TermInfo termInfo = indexEnum.termInfo();
			indexToTerms[i] = baos.size();
			outputStream.writeVInt(fieldCounter);
			outputStream.writeString(term.text());
			outputStream.writeVInt(termInfo.docFreq);
			outputStream.writeVInt(termInfo.skipOffset);
			outputStream.writeVLong(termInfo.freqPointer);
			outputStream.writeVLong(termInfo.proxPointer);
			outputStream.writeVLong(indexEnum.indexPointer);
			for (int j = 1; j < indexDivisor; j++)
				if (!indexEnum.next())
					break;
		}
		outputStream.close();
		fields = new Term[fieldStrs.size()];
		for (int i = 0; i < fields.length; i++) {
			fields[i] = new Term(fieldStrs.get(i));
		}
		this.data = baos.toByteArray();
		instantOn.save(this,directory,segment);
	}