outFile += NS_LITERAL_CSTRING(".out");
outFile.AppendLiteral(".out");
TestAsyncWrite(const char* fileName, PRUint32 offset, PRInt32 length){    nsresult rv;    PRINTF(("TestAsyncWrite\n"));    nsCOMPtr<nsIFileTransportService> fts =              do_GetService(kFileTransportServiceCID, &rv);    if (NS_FAILED(rv)) return rv;    nsCAutoString outFile(fileName);    outFile += NS_LITERAL_CSTRING(".out");    nsITransport* fileTrans;    nsCOMPtr<nsILocalFile> file;    rv = NS_NewNativeLocalFile(outFile, PR_FALSE, getter_AddRefs(file));    if (NS_FAILED(rv)) return rv;    rv = fts->CreateTransport(file,                              PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,                              0664, PR_TRUE, &fileTrans);    if (NS_FAILED(rv)) return rv;    MyListener* listener = new MyListener();    if (listener == nsnull)        return NS_ERROR_OUT_OF_MEMORY;    NS_ADDREF(listener);    rv = listener->Init(outFile.get());    if (NS_FAILED(rv)) return rv;    MyProgressEventSink* progressSink = new MyProgressEventSink();    if (progressSink == nsnull)        return NS_ERROR_OUT_OF_MEMORY;    NS_ADDREF(progressSink);    rv = fileTrans->SetNotificationCallbacks(progressSink, PR_FALSE);    if (NS_FAILED(rv)) return rv;    nsCOMPtr<nsILocalFile> f;    rv = NS_NewNativeLocalFile(nsDependentCString(fileName), PR_FALSE, getter_AddRefs(f));    if (NS_FAILED(rv)) return rv;    nsCOMPtr<nsIInputStream> inStr;    rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), f);    if (NS_FAILED(rv)) return rv;    gDone = PR_FALSE;    nsCOMPtr<nsIRequest> request;    rv = NS_AsyncWriteFromStream(getter_AddRefs(request), fileTrans, inStr, offset, length, 0, listener);    if (NS_FAILED(rv)) return rv;    while (!gDone) {        PLEvent* event;        rv = gEventQ->WaitForEvent(&event);        if (NS_FAILED(rv)) return rv;        rv = gEventQ->HandleEvent(event);        if (NS_FAILED(rv)) return rv;    }    NS_RELEASE(listener);    NS_RELEASE(fileTrans);    return NS_OK;}