本文整理汇总了C++中NS_NewLocalFileInputStream函数的典型用法代码示例。如果您正苦于以下问题:C++ NS_NewLocalFileInputStream函数的具体用法?C++ NS_NewLocalFileInputStream怎么用?C++ NS_NewLocalFileInputStream使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NS_NewLocalFileInputStream函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NS_ENSURE_SUCCESS
nsresult
LookupCache::Open()
{
nsCOMPtr<nsIFile> storeFile;
nsresult rv = mStoreDirectory->Clone(getter_AddRefs(storeFile));
NS_ENSURE_SUCCESS(rv, rv);
rv = storeFile->AppendNative(mTableName + NS_LITERAL_CSTRING(CACHE_SUFFIX));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInputStream> inputStream;
rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), storeFile,
PR_RDONLY | nsIFile::OS_READAHEAD);
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) {
Reset();
return rv;
}
if (rv == NS_ERROR_FILE_NOT_FOUND) {
// Simply lacking a .cache file is a recoverable error,
// as unlike the .pset/.sbstore files it is a pure cache.
// Just create a new empty one.
ClearCompleteCache();
} else {
// Read in the .cache file
rv = ReadHeader(inputStream);
NS_ENSURE_SUCCESS(rv, rv);
LOG(("ReadCompletions"));
rv = ReadCompletions(inputStream);
NS_ENSURE_SUCCESS(rv, rv);
rv = inputStream->Close();
NS_ENSURE_SUCCESS(rv, rv);
}
LOG(("Loading PrefixSet"));
rv = LoadPrefixSet();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
示例2: NS_NewLocalFileInputStream
void
FileBlobImpl::GetInternalStream(nsIInputStream** aStream, ErrorResult& aRv)
{
nsCOMPtr<nsIInputStream> stream;
aRv = NS_NewLocalFileInputStream(getter_AddRefs(stream), mFile, -1, -1,
sFileStreamFlags);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
if (mWholeFile) {
stream.forget(aStream);
return;
}
RefPtr<SlicedInputStream> slicedInputStream =
new SlicedInputStream(stream, mStart, mLength);
slicedInputStream.forget(aStream);
}
示例3: NS_NewLocalFileInputStream
already_AddRefed<nsISupports>
DOMFileHandle::CreateStream(nsIFile* aFile, bool aReadOnly)
{
nsresult rv;
if (aReadOnly) {
nsCOMPtr<nsIInputStream> stream;
rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), aFile, -1, -1,
nsIFileInputStream::DEFER_OPEN);
NS_ENSURE_SUCCESS(rv, nullptr);
return stream.forget();
}
nsCOMPtr<nsIFileStream> stream;
rv = NS_NewLocalFileStream(getter_AddRefs(stream), aFile, -1, -1,
nsIFileStream::DEFER_OPEN);
NS_ENSURE_SUCCESS(rv, nullptr);
return stream.forget();
}
示例4: NS_ENSURE_ARG_POINTER
NS_IMETHODIMP
nsMsgMaildirStore::GetMsgInputStream(nsIMsgFolder *aMsgFolder,
const nsACString &aMsgToken,
int64_t *aOffset,
nsIMsgDBHdr *aMsgHdr,
bool *aReusable,
nsIInputStream **aResult)
{
NS_ENSURE_ARG_POINTER(aMsgFolder);
NS_ENSURE_ARG_POINTER(aOffset);
NS_ENSURE_ARG_POINTER(aResult);
*aReusable = false; // message per file
*aOffset = 0;
// construct path to file
nsCOMPtr<nsIFile> path;
nsresult rv = aMsgFolder->GetFilePath(getter_AddRefs(path));
NS_ENSURE_SUCCESS(rv, rv);
if (aMsgToken.IsEmpty())
{
PR_LOG(MailDirLog, PR_LOG_ALWAYS,
("GetMsgInputStream - empty storeToken!!\n"));
return NS_ERROR_FAILURE;
}
path->Append(NS_LITERAL_STRING("cur"));
path->AppendNative(aMsgToken);
// let's check if the folder exists
bool exists;
path->Exists(&exists);
if (!exists) {
PR_LOG(MailDirLog, PR_LOG_ALWAYS,
("GetMsgInputStream - oops! cur subfolder does not exist!\n"));
rv = path->Create(nsIFile::DIRECTORY_TYPE, 0755);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_NewLocalFileInputStream(aResult, path);
}
示例5: RunTest
/**
* asynchronously copy file.
*/
static nsresult
RunTest(nsIFile *srcFile, nsIFile *destFile)
{
nsresult rv;
LOG(("RunTest\n"));
nsCOMPtr<nsIStreamTransportService> sts =
do_GetService(kStreamTransportServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIInputStream> srcStr;
rv = NS_NewLocalFileInputStream(getter_AddRefs(srcStr), srcFile);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIOutputStream> destStr;
rv = NS_NewLocalFileOutputStream(getter_AddRefs(destStr), destFile);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsITransport> srcTransport;
rv = sts->CreateInputTransport(srcStr, PRInt64(-1), PRInt64(-1), PR_TRUE,
getter_AddRefs(srcTransport));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsITransport> destTransport;
rv = sts->CreateOutputTransport(destStr, PRInt64(-1), PRInt64(-1), PR_TRUE,
getter_AddRefs(destTransport));
if (NS_FAILED(rv)) return rv;
MyCopier *copier = new MyCopier();
if (copier == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(copier);
rv = copier->AsyncCopy(srcTransport, destTransport);
if (NS_FAILED(rv)) return rv;
PumpEvents();
NS_RELEASE(copier);
return NS_OK;
}
示例6: lock
nsresult
VariableLengthPrefixSet::LoadFromFile(nsIFile* aFile)
{
MutexAutoLock lock(mLock);
NS_ENSURE_ARG_POINTER(aFile);
Telemetry::AutoTimer<Telemetry::URLCLASSIFIER_VLPS_FILELOAD_TIME> timer;
nsCOMPtr<nsIInputStream> localInFile;
nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(localInFile), aFile,
PR_RDONLY | nsIFile::OS_READAHEAD);
NS_ENSURE_SUCCESS(rv, rv);
// Calculate how big the file is, make sure our read buffer isn't bigger
// than the file itself which is just wasting memory.
int64_t fileSize;
rv = aFile->GetFileSize(&fileSize);
NS_ENSURE_SUCCESS(rv, rv);
if (fileSize < 0 || fileSize > UINT32_MAX) {
return NS_ERROR_FAILURE;
}
uint32_t bufferSize = std::min<uint32_t>(static_cast<uint32_t>(fileSize),
MAX_BUFFER_SIZE);
// Convert to buffered stream
nsCOMPtr<nsIInputStream> in;
rv = NS_NewBufferedInputStream(getter_AddRefs(in), localInFile.forget(),
bufferSize);
NS_ENSURE_SUCCESS(rv, rv);
rv = mFixedPrefixSet->LoadPrefixes(in);
NS_ENSURE_SUCCESS(rv, rv);
rv = LoadPrefixes(in);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;;
}
示例7: RunTest
/**
* asynchronously copy file.
*/
static nsresult
RunTest(nsIFile *file, int64_t offset, int64_t length)
{
nsresult rv;
LOG(("RunTest\n"));
nsCOMPtr<nsIInputStream> stream;
rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), file);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIInputStreamPump> pump;
rv = NS_NewInputStreamPump(getter_AddRefs(pump), stream, offset, length);
if (NS_FAILED(rv)) return rv;
rv = pump->AsyncRead(new MyListener(), nullptr);
if (NS_FAILED(rv)) return rv;
PumpEvents();
return NS_OK;
}
示例8: getter_AddRefs
nsresult
nsFileChannel::MakeFileInputStream(nsIFile *file,
nsCOMPtr<nsIInputStream> &stream,
nsCString &contentType,
bool async)
{
// we accept that this might result in a disk hit to stat the file
bool isDir;
nsresult rv = file->IsDirectory(&isDir);
if (NS_FAILED(rv)) {
// canonicalize error message
if (rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
rv = NS_ERROR_FILE_NOT_FOUND;
if (async && (NS_ERROR_FILE_NOT_FOUND == rv)) {
// We don't return "Not Found" errors here. Since we could not find
// the file, it's not a directory anyway.
isDir = false;
} else {
return rv;
}
}
if (isDir) {
rv = nsDirectoryIndexStream::Create(file, getter_AddRefs(stream));
if (NS_SUCCEEDED(rv) && !HasContentTypeHint())
contentType.AssignLiteral(APPLICATION_HTTP_INDEX_FORMAT);
} else {
rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), file, -1, -1,
async? nsIFileInputStream::DEFER_OPEN : 0);
if (NS_SUCCEEDED(rv) && !HasContentTypeHint()) {
// Use file extension to infer content type
nsCOMPtr<nsIMIMEService> mime = do_GetService("@mozilla.org/mime;1", &rv);
if (NS_SUCCEEDED(rv)) {
mime->GetTypeFromFile(file, contentType);
}
}
}
return rv;
}
示例9: NS_NewLocalFileInputStream
nsresult nsTextAddress::ReadRecordNumber(nsIFile *aSrc, nsCString &aLine, PRInt32 rNum)
{
nsCOMPtr<nsIInputStream> inputStream;
nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), aSrc);
if (NS_FAILED(rv)) {
IMPORT_LOG0( "*** Error opening address file for reading\n");
return rv;
}
PRInt32 rIndex = 0;
PRUint32 bytesLeft = 0;
rv = inputStream->Available(&bytesLeft);
if (NS_FAILED(rv)) {
IMPORT_LOG0( "*** Error checking address file for eof\n");
inputStream->Close();
return rv;
}
nsCOMPtr<nsILineInputStream> lineStream(do_QueryInterface(inputStream, &rv));
NS_ENSURE_SUCCESS(rv, rv);
bool more = true;
while (more && (rIndex <= rNum)) {
rv = ReadRecord(lineStream, aLine, &more);
if (NS_FAILED(rv)) {
inputStream->Close();
return rv;
}
if (rIndex == rNum) {
inputStream->Close();
return NS_OK;
}
rIndex++;
}
return NS_ERROR_FAILURE;
}
示例10: RunBlockingTest
static nsresult
RunBlockingTest(nsIFile *srcFile, nsIFile *destFile)
{
nsresult rv;
LOG(("RunBlockingTest\n"));
nsCOMPtr<nsIStreamTransportService> sts =
do_GetService(kStreamTransportServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIInputStream> srcIn;
rv = NS_NewLocalFileInputStream(getter_AddRefs(srcIn), srcFile);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIOutputStream> fileOut;
rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileOut), destFile);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsITransport> destTransport;
rv = sts->CreateOutputTransport(fileOut, PRInt64(-1), PRInt64(-1),
PR_TRUE, getter_AddRefs(destTransport));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIOutputStream> destOut;
rv = destTransport->OpenOutputStream(nsITransport::OPEN_BLOCKING, 100, 10, getter_AddRefs(destOut));
if (NS_FAILED(rv)) return rv;
char buf[120];
PRUint32 n;
for (;;) {
rv = srcIn->Read(buf, sizeof(buf), &n);
if (NS_FAILED(rv) || (n == 0)) return rv;
rv = destOut->Write(buf, n, &n);
if (NS_FAILED(rv)) return rv;
}
return NS_OK;
}
示例11: NS_NewLocalFile
void nsBrowserListener::GetProperty(nsIPersistentProperties **prop,nsACString &fileName)
{
nsresult rv;
nsCOMPtr<nsIPersistentProperties> tmpprop=do_CreateInstance("@mozilla.org/persistent-properties;1", &rv);
if (NS_FAILED(rv))
{
LOG<<"Get properties Error:"<<rv<<"\n";
}
nsCOMPtr<nsILocalFile> file;
rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(fileName), PR_FALSE,
getter_AddRefs(file));
if (NS_FAILED(rv))
return ;
nsCOMPtr<nsIInputStream> fistream;
rv=NS_NewLocalFileInputStream(getter_AddRefs(fistream), file);
if (NS_FAILED(rv))
{
return ;
}
tmpprop->Load(fistream);
*prop=tmpprop;
NS_ADDREF(*prop);
}
示例12: NS_NewLocalFileInputStream
// virtual
already_AddRefed<nsISupports>
FileHandle::CreateStream(nsIFile* aFile, bool aReadOnly)
{
nsresult rv;
if (aReadOnly) {
nsCOMPtr<nsIInputStream> stream;
rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), aFile, -1, -1,
nsIFileInputStream::DEFER_OPEN);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
return stream.forget();
}
nsCOMPtr<nsIFileStream> stream;
rv = NS_NewLocalFileStream(getter_AddRefs(stream), aFile, -1, -1,
nsIFileStream::DEFER_OPEN);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
return stream.forget();
}
示例13: NS_ASSERTION
nsresult
FileMediaResource::Open(nsIStreamListener** aStreamListener)
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
MOZ_ASSERT(aStreamListener);
*aStreamListener = nullptr;
nsresult rv = NS_OK;
// The channel is already open. We need a synchronous stream that
// implements nsISeekableStream, so we have to find the underlying
// file and reopen it
nsCOMPtr<nsIFileChannel> fc(do_QueryInterface(mChannel));
if (fc) {
nsCOMPtr<nsIFile> file;
rv = fc->GetFile(getter_AddRefs(file));
NS_ENSURE_SUCCESS(rv, rv);
rv = NS_NewLocalFileInputStream(
getter_AddRefs(mInput), file, -1, -1, nsIFileInputStream::SHARE_DELETE);
} else if (IsBlobURI(mURI)) {
rv = NS_GetStreamForBlobURI(mURI, getter_AddRefs(mInput));
}
NS_ENSURE_SUCCESS(rv, rv);
mSeekable = do_QueryInterface(mInput);
if (!mSeekable) {
// XXX The file may just be a .url or similar
// shortcut that points to a Web site. We need to fix this by
// doing an async open and waiting until we locate the real resource,
// then using that (if it's still a file!).
return NS_ERROR_FAILURE;
}
return NS_OK;
}
示例14: NS_NewLocalFileInputStream
nsresult
nsMsgAttachmentHandler::LoadDataFromFile(nsILocalFile *file, nsString &sigData, bool charsetConversion)
{
PRInt32 readSize;
char *readBuf;
nsCOMPtr <nsIInputStream> inputFile;
nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(inputFile), file);
if (NS_FAILED(rv))
return NS_MSG_ERROR_WRITING_FILE;
PRInt64 fileSize;
file->GetFileSize(&fileSize);
readSize = (PRUint32) fileSize;
readBuf = (char *)PR_Malloc(readSize + 1);
if (!readBuf)
return NS_ERROR_OUT_OF_MEMORY;
memset(readBuf, 0, readSize + 1);
PRUint32 bytesRead;
inputFile->Read(readBuf, readSize, &bytesRead);
inputFile->Close();
nsDependentCString cstringReadBuf(readBuf, bytesRead);
if (charsetConversion)
{
if (NS_FAILED(ConvertToUnicode(m_charset.get(), cstringReadBuf, sigData)))
CopyASCIItoUTF16(cstringReadBuf, sigData);
}
else
CopyASCIItoUTF16(cstringReadBuf, sigData);
PR_FREEIF(readBuf);
return NS_OK;
}
示例15: NS_GetSpecialDirectory
nsresult nsReadConfig::openAndEvaluateJSFile(const char *aFileName, PRInt32 obscureValue,
bool isEncoded,
bool isBinDir)
{
nsresult rv;
nsCOMPtr<nsIInputStream> inStr;
if (isBinDir) {
nsCOMPtr<nsIFile> jsFile;
rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR,
getter_AddRefs(jsFile));
if (NS_FAILED(rv))
return rv;
rv = jsFile->AppendNative(nsDependentCString(aFileName));
if (NS_FAILED(rv))
return rv;
rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
if (NS_FAILED(rv))
return rv;
} else {
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
if (NS_FAILED(rv))
return rv;
nsCAutoString location("resource://gre/defaults/autoconfig/");
location += aFileName;
nsCOMPtr<nsIURI> uri;
rv = ioService->NewURI(location, nsnull, nsnull, getter_AddRefs(uri));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIChannel> channel;
rv = ioService->NewChannelFromURI(uri, getter_AddRefs(channel));
if (NS_FAILED(rv))
return rv;
rv = channel->Open(getter_AddRefs(inStr));
if (NS_FAILED(rv))
return rv;
}
PRUint32 fs, amt = 0;
inStr->Available(&fs);
char *buf = (char *)PR_Malloc(fs * sizeof(char));
if (!buf)
return NS_ERROR_OUT_OF_MEMORY;
rv = inStr->Read(buf, fs, &amt);
NS_ASSERTION((amt == fs), "failed to read the entire configuration file!!");
if (NS_SUCCEEDED(rv)) {
if (obscureValue > 0) {
// Unobscure file by subtracting some value from every char.
for (PRUint32 i = 0; i < amt; i++)
buf[i] -= obscureValue;
}
rv = EvaluateAdminConfigScript(buf, amt, aFileName,
false, true,
isEncoded ? true:false);
}
inStr->Close();
PR_Free(buf);
return rv;
}