protected synchronized void saveAs(BufferFile outFile, Long newDatabaseId,
			boolean associateWithNewFile, TaskMonitor monitor)
			throws IOException, CancelledException {

		checkIsClosed();

		if (txStarted) {
			throw new IllegalStateException("Can't save during transaction");
		}

		try {
			long txId = startTransaction();
			try {
				if (newDatabaseId == null) {
					initDatabaseId();
				}
				else if (databaseId != newDatabaseId.longValue()) {
					setDatabaseId(newDatabaseId);
				}
				masterTable.flush();
			}
			finally {
				endTransaction(txId, true); // saved file may be corrupt on IOException
			}

			bufferMgr.saveAs(outFile, associateWithNewFile, monitor);
		}
		finally {
			cacheChangedState();
		}
	}
Save the database to the specified buffer file and a newDatabaseId.
Open handle will always be associated with the new file.
NOTE: This method is intended for use in transforming one database to
match another existing database.
@param outFile buffer file open for writing
@param newDatabaseId database ID to be forced for new database or null to generate 
new database ID
@param associateWithNewFile if true the outFile will be associated with this DBHandle as the 
current source file, if false no change will be made to this DBHandle's state and the outFile
will be written and set as read-only.  The caller is responsbile for disposing the outFile if 
this parameter is false.
@param monitor progress monitor
@throws IOException if IO error occurs
@throws CancelledException if monitor cancels operation
Ghidra/Framework/DB/src/main/java/db/DBHandle.java