class VersionFile {

	VersionFile(LocalBufferFile originalBf, LocalBufferFile targetBf, File vfile) throws IOException {
		
		bufferSize = originalBf.getBufferSize();
		originalBufCount = originalBf.getIndexCount();
		initialBufCount = 0; // new file
		
		file = vfile;
		readOnly = false;
		versionFile = new LocalBufferFile(vfile, bufferSize);
		vfIndexProvider = new IndexProvider();
		
		// Save magic number for version file
		versionFile.setParameter(MAGIC_NUMBER_PARM, MAGIC_NUMBER);
		
		// Save original and target file IDs as user paramater values
		originalFileId = originalBf.getFileId();
		versionFile.setParameter(ORIGINAL_FILE_ID_HI_PARM, (int)(originalFileId >> 32));
		versionFile.setParameter(ORIGINAL_FILE_ID_LOW_PARM, (int)(originalFileId & 0xffffffffL));
		targetFileId = targetBf.getFileId();
		
		// Save original buffer count
		versionFile.setParameter(ORIGINAL_BUFFER_COUNT_PARM, originalBufCount);
		
		// Create first map buffer (buffer ID is same as index)
		bufferIndexMap = new IntIntHashtable();
		newMapIds = new IntArrayList();
		lastMapBuffer = new DataBuffer(bufferSize);
		lastMapIndex = vfIndexProvider.allocateIndex();
		lastMapBuffer.setId(lastMapIndex);
		lastMapBuffer.putInt(NEXT_BUFFER_INDEX_OFFSET, -1);
		lastMapBuffer.putInt(FIRST_ENTRY_OFFSET, -1);
		nextMapEntryOffset = FIRST_ENTRY_OFFSET;
		versionFile.put(lastMapBuffer, lastMapIndex);
		versionFile.setParameter(MAP_BUFFER_INDEX_PARM, lastMapIndex);
		
		// Save original free list
		freeIndexes = originalBf.getFreeIndexes();
		Arrays.sort(freeIndexes);
		int freeListIndex = saveFreeIndexList();
		versionFile.setParameter(FREE_LIST_BUFFER_INDEX_PARM, freeListIndex);
		versionFile.setParameter(FREE_LIST_SIZE_PARM, freeIndexes.length);
		
		// Copy original parameter values
		String[] parmNames = originalBf.getParameterNames();
		for (int i = 0; i < parmNames.length; i++) {
			String name = parmNames[i];
			versionFile.setParameter(name, originalBf.getParameter(name));
		}
		
	}

	  VersionFile(LocalBufferFile originalBf, LocalBufferFile targetBf, File vfile);
	  VersionFile(File vfile);
	  VersionFile(BufferFile versionFile);

}