nsSaveAsListener::OnDataAvailable(nsIChannel* aChannel,
nsSaveMsgListener::OnDataAvailable(nsIChannel* aChannel,
nsSaveAsListener::OnDataAvailable(nsIChannel* aChannel,                                   nsISupports* aSupport,                                  nsIInputStream* inStream,                                   PRUint32 srcOffset,                                  PRUint32 count){  nsresult rv = NS_ERROR_FAILURE;  if (m_dataBuffer && m_outputStream)  {    PRUint32 available, readCount, maxReadCount = FOUR_K;    PRUint32 writeCount;    rv = inStream->Available(&available);    while (NS_SUCCEEDED(rv) && available)    {      if (maxReadCount > available)        maxReadCount = available;      nsCRT::memset(m_dataBuffer, 0, FOUR_K+1);      rv = inStream->Read(m_dataBuffer, maxReadCount, &readCount);      // rhp:      // Ok, now we do one of two things. If we are sending out HTML, then      // just write it to the HTML stream as it comes along...but if this is      // a save as TEXT operation, we need to buffer this up for conversion       // when we are done. When the stream converter for HTML-TEXT gets in place,      // this magic can go away.      //      if (NS_SUCCEEDED(rv))      {        if ( (m_doCharsetConversion) && (m_outputFormat.EqualsWithConversion(TEXT_PLAIN)) )        {          PRUnichar       *u = nsnull;           nsAutoString    fmt; fmt.AssignWithConversion("%s");                    u = nsTextFormatter::smprintf(fmt.GetUnicode(), m_dataBuffer); // this converts UTF-8 to UCS-2           if (u)          {            PRInt32   newLen = nsCRT::strlen(u);            m_msgBuffer.Append(u, newLen);            PR_FREEIF(u);          }          else            m_msgBuffer.AppendWithConversion(m_dataBuffer, readCount);        }        else        {          rv = m_outputStream->Write(m_dataBuffer, readCount, &writeCount);        }        available -= readCount;      }    }  }  return rv;}