public void finish() throws IOException {

		if (state != State.INUSE) {
			throw new IllegalStateException("FileSaver not in use");
		}
		
		// Ensure both are closed before we try to rename.
		if (mOutputStream != null) {
			mOutputStream.close();
		}
		if (mWriter != null) {
			mWriter.close();
		}

		// Delete the previous backup file if it exists;
		if (backupFile.exists() && !backupFile.delete()) {
			throw new IOException("Failed to delete backup file " + backupFile);
		}

		// Rename the user's previous file to itsName.bak,
		// UNLESS this is a new file ;
		if (inputFile.exists() && !inputFile.renameTo(backupFile)) {
			throw new IOException("Could not rename file to backup file " + backupFile);
		}

		// Rename the temporary file to the save file.
		if (!tmpFile.renameTo(inputFile)) {
			throw new IOException("Could not rename temp file to save file");
		}
		state = State.AVAILABLE;
	}