private CopyStates doCopy(final Context context, final NotificationCompat.Builder notification, final Runnable updateForegroundNotification, final InputStream inputStream, final Uri outputUri) {
        OutputStream outputStream = null;
        long lastPublishTime = System.currentTimeMillis();
        try {
            outputStream = new BufferedOutputStream(ContentStorage.get().openForWrite(outputUri));
            final byte[] buffer = new byte[8192];
            int length = 0;
            while (!cancelled.get() && (length = inputStream.read(buffer)) > 0) {
                outputStream.write(buffer, 0, length);
                bytesCopied += length;
                if ((System.currentTimeMillis() - lastPublishTime) > 500) { // avoid message flooding
                    notification.setContentText(context.getString(R.string.receivedownload_amount_copied, Formatter.formatBytes(bytesCopied)));
                    updateForegroundNotification.run();
                    lastPublishTime = System.currentTimeMillis();
                }
            }
            return CopyStates.SUCCESS;
        } catch (IOException e) {
            Log.e("IOException on receiving map file: " + e.getMessage());
            return CopyStates.IO_EXCEPTION;
        } finally {
            IOUtils.closeQuietly(inputStream, outputStream);
        }
    }
check whether the target file or its companion file already exist, and delete both, if so
main/src/main/java/cgeo/geocaching/downloader/ReceiveDownload.java