/// <summary>Copies the stream contents to a temporary file.</summary>
 /// <remarks>
 /// Copies the stream contents to a temporary file.  If the copy is
 /// successful, the temporary file will be renamed to the real path,
 /// else the temporary file will be deleted.
 /// </remarks>
 /// <param name="in">the input stream for the copy</param>
 /// <param name="target">where to store the contents of the stream</param>
 /// <exception cref="System.IO.IOException">if copy fails</exception>
 protected internal virtual void CopyStreamToTarget(InputStream @in, PathData target
                                                    )
 {
     if (target.exists && (target.stat.IsDirectory() || !overwrite))
     {
         throw new PathExistsException(target.ToString());
     }
     CommandWithDestination.TargetFileSystem targetFs = new CommandWithDestination.TargetFileSystem
                                                            (target.fs);
     try
     {
         PathData tempTarget = target.Suffix("._COPYING_");
         targetFs.SetWriteChecksum(writeChecksum);
         targetFs.WriteStreamToFile(@in, tempTarget, lazyPersist);
         targetFs.Rename(tempTarget, target);
     }
     finally
     {
         targetFs.Close();
     }
 }