mInputStream = new nsInputFileStream(*fileSpec); if (mInputStream) { if (! mInputStream->is_open()) { delete mInputStream; mInputStream = nsnull; } }
rv = NS_NewLocalFileInputStream(getter_AddRefs(mInputStream), aFile, PR_RDONLY, -1, 0); NS_ENSURE_SUCCESS(rv, rv);
BookmarkParser::Init(nsFileSpec *fileSpec, nsIRDFDataSource *aDataSource,                      PRBool aIsImportOperation){    mDataSource = aDataSource;    mFoundIEFavoritesRoot = PR_FALSE;    mFoundPersonalToolbarFolder = PR_FALSE;    mIsImportOperation = aIsImportOperation;    nsresult rv;    // determine default platform charset...    nsCOMPtr<nsIPlatformCharset> platformCharset =         do_GetService(kPlatformCharsetCID, &rv);    if (NS_SUCCEEDED(rv) && (platformCharset))    {        nsAutoString    defaultCharset;        if (NS_SUCCEEDED(rv = platformCharset->GetCharset(kPlatformCharsetSel_4xBookmarkFile, defaultCharset)))        {            // found the default platform charset, now try and get a decoder from it to Unicode            nsCOMPtr<nsICharsetConverterManager> charsetConv =                 do_GetService(kCharsetConverterManagerCID, &rv);            if (NS_SUCCEEDED(rv) && (charsetConv))            {                rv = charsetConv->GetUnicodeDecoder(&defaultCharset, getter_AddRefs(mUnicodeDecoder));            }        }    }    nsCAutoString   str;    BookmarkField   *field;    for (field = gBookmarkFieldTable; field->mName; ++field)    {        str = field->mPropertyName;        rv = gRDF->GetResource(str, &field->mProperty);        if (NS_FAILED(rv))  return rv;    }    for (field = gBookmarkHeaderFieldTable; field->mName; ++field)    {        str = field->mPropertyName;        rv = gRDF->GetResource(str, &field->mProperty);        if (NS_FAILED(rv))  return rv;    }    if (fileSpec)    {        mContentsLen = fileSpec->GetFileSize();        if (mContentsLen > 0)        {            mContents = new char [mContentsLen + 1];            if (mContents)            {                nsInputFileStream inputStream(*fileSpec);   // defaults to read only                PRInt32 howMany = inputStream.read(mContents, mContentsLen);                if (PRUint32(howMany) == mContentsLen)                {                    mContents[mContentsLen] = '\0';                }                else                {                    delete [] mContents;                    mContents = nsnull;                }            }        }        if (!mContents)        {            // we were unable to read in the entire bookmark file at once,            // so let's try reading it in a bit at a time instead            mInputStream = new nsInputFileStream(*fileSpec);            if (mInputStream)            {                if (! mInputStream->is_open())                {                    delete mInputStream;                    mInputStream = nsnull;                }            }        }    }    return NS_OK;}