nsCOMPtr<nsIInternetSearchContext> context (do_QueryInterface(ctxt)); if (!context)	return(NS_ERROR_NO_INTERFACE);
InternetSearchDataSource::OnDataAvailable(nsIRequest *request, nsISupports *ctxt,				nsIInputStream *aIStream, PRUint32 sourceOffset, PRUint32 aLength){	if (!ctxt)	return(NS_ERROR_NO_INTERFACE);	nsCOMPtr<nsIInternetSearchContext> context (do_QueryInterface(ctxt));	if (!context)	return(NS_ERROR_NO_INTERFACE);	nsresult	rv = NS_OK;	if (aLength < 1)	return(rv);	PRUint32	count;	char		*buffer = new char[ aLength ];	if (!buffer)	return(NS_ERROR_OUT_OF_MEMORY);	if (NS_FAILED(rv = aIStream->Read(buffer, aLength, &count)) || count == 0)	{#ifdef	DEBUG		printf("Search datasource read failure.\n");#endif		delete []buffer;		return(rv);	}	if (count != aLength)	{#ifdef	DEBUG		printf("Search datasource read # of bytes failure.\n");#endif		delete []buffer;		return(NS_ERROR_UNEXPECTED);	}	nsCOMPtr<nsIUnicodeDecoder>	decoder;	context->GetUnicodeDecoder(getter_AddRefs(decoder));	if (decoder)	{		char			*aBuffer = buffer;		PRInt32			unicharBufLen = 0;		decoder->GetMaxLength(aBuffer, aLength, &unicharBufLen);		PRUnichar		*unichars = new PRUnichar [ unicharBufLen+1 ];		do		{			PRInt32		srcLength = aLength;			PRInt32		unicharLength = unicharBufLen;			rv = decoder->Convert(aBuffer, &srcLength, unichars, &unicharLength);			unichars[unicharLength]=0;  //add this since the unicode converters can't be trusted to do so.			// Move the nsParser.cpp 00 -> space hack to here so it won't break UCS2 file			// Hack Start			for(PRInt32 i=0;i < unicharLength; i++)			{				if(0x0000 == unichars[i])				{					unichars[i] = PRUnichar(' ');				}			}			// Hack End			context->AppendUnicodeBytes(unichars, unicharLength);			// if we failed, we consume one byte by replace it with U+FFFD			// and try conversion again.			if(NS_FAILED(rv))			{				decoder->Reset();				unsigned char	smallBuf[2];				smallBuf[0] = 0xFF;				smallBuf[1] = 0xFD;				context->AppendBytes( (const char *)&smallBuf, 2L);				if(((PRUint32) (srcLength + 1)) > aLength)					srcLength = aLength;				else 					srcLength++;				aBuffer += srcLength;				aLength -= srcLength;			}		} while (NS_FAILED(rv) && (aLength > 0));		delete [] unichars;		unichars = nsnull;	}	else	{		context->AppendBytes(buffer, aLength);	}	delete [] buffer;	buffer = nsnull;	return(rv);}