Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes
nsSafeFileOutputStream Class Reference

#include <nsFileStreams.h>

Inheritance diagram for nsSafeFileOutputStream:
Inheritance graph
[legend]
Collaboration diagram for nsSafeFileOutputStream:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSISAFEOUTPUTSTREAM 
nsSafeFileOutputStream ()
virtual ~nsSafeFileOutputStream ()
NS_IMETHODIMP Close ()
NS_IMETHODIMP Write (const char *buf, PRUint32 count, PRUint32 *result)
NS_IMETHODIMP Init (nsIFile *file, PRInt32 ioFlags, PRInt32 perm, PRInt32 behaviorFlags)
nsresult InitWithFileDescriptor (PRFileDesc *fd, nsISupports *parent)
void seek (in long whence, in long long offset)
 seek
long long tell ()
 tell
void setEOF ()
 setEOF
void init (in nsIFile file, in long ioFlags, in long perm, in long behaviorFlags)
void close ()
 Close the stream.
void flush ()
 Flush the stream.
unsigned long write (in string aBuf, in unsigned long aCount)
 Write data into the stream.
unsigned long writeFrom (in nsIInputStream aFromStream, in unsigned long aCount)
 Writes data into the stream from an input stream.
unsigned long writeSegments (in nsReadSegmentFun aReader, in voidPtr aClosure, in unsigned long aCount)
 Low-level write method that has access to the stream's underlying buffer.
boolean isNonBlocking ()
void finish ()
 Call this method to close the stream and cause the original target to be overwritten.

Static Public Member Functions

static NS_METHOD Create (nsISupports *aOuter, REFNSIID aIID, void **aResult)

Public Attributes

const PRInt32 NS_SEEK_SET = 0
const PRInt32 NS_SEEK_CUR = 1
const PRInt32 NS_SEEK_END = 2

Protected Attributes

nsCOMPtr< nsIFilemTargetFile
nsCOMPtr< nsIFilemTempFile
PRBool mTargetFileExists
nsresult mWriteResult
PRFileDescmFD
nsCOMPtr< nsISupports > mParent
PRBool mCloseFD

Detailed Description

Definition at line 157 of file nsFileStreams.h.


Constructor & Destructor Documentation

Definition at line 164 of file nsFileStreams.h.

virtual nsSafeFileOutputStream::~nsSafeFileOutputStream ( ) [inline, virtual]

Definition at line 168 of file nsFileStreams.h.

Here is the call graph for this function:


Member Function Documentation

void nsIOutputStream::close ( ) [inherited]

Close the stream.

Forces the output stream to flush any buffered data.

Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif unable to flush without blocking the calling thread (non-blocking mode only)

Reimplemented from nsFileStream.

Definition at line 543 of file nsFileStreams.cpp.

{
    nsresult rv = nsFileOutputStream::Close();

    // the consumer doesn't want the original file overwritten -
    // so clean up by removing the temp file.
    if (mTempFile) {
        mTempFile->Remove(PR_FALSE);
        mTempFile = nsnull;
    }

    return rv;
}

Here is the caller graph for this function:

static NS_METHOD nsFileOutputStream::Create ( nsISupports *  aOuter,
REFNSIID  aIID,
void **  aResult 
) [static, inherited]

Call this method to close the stream and cause the original target to be overwritten.

Note: if any call to |write| failed to write out all of the data given to it, then calling this method will |close| the stream and return failure. Further, if closing the stream fails, this method will return failure. The original target will be overwritten only if all calls to |write| succeeded and the stream was successfully closed.

void nsIOutputStream::flush ( ) [inherited]

Flush the stream.

Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif unable to flush without blocking the calling thread (non-blocking mode only)
void nsIFileOutputStream::init ( in nsIFile  file,
in long  ioFlags,
in long  perm,
in long  behaviorFlags 
) [inherited]
Parameters:
file- file to write to (must QI to nsILocalFile)
ioFlags- file open flags listed in prio.h
perm- file mode bits listed in prio.h
behaviorFlagsflags specifying various behaviors of the class (currently none supported)
NS_IMETHODIMP nsSafeFileOutputStream::Init ( nsIFile file,
PRInt32  ioFlags,
PRInt32  perm,
PRInt32  behaviorFlags 
)
nsresult nsFileStream::InitWithFileDescriptor ( PRFileDesc fd,
nsISupports *  parent 
) [inherited]

Definition at line 106 of file nsFileStreams.cpp.

{
    NS_ENSURE_TRUE(mFD == nsnull, NS_ERROR_ALREADY_INITIALIZED);
    //
    // this file stream is dependent on its parent to keep the
    // file descriptor valid.  an owning reference to the parent
    // prevents the file descriptor from going away prematurely.
    //
    mFD = fd;
    mCloseFD = PR_FALSE;
    mParent = parent;
    return NS_OK;
}
Returns:
true if stream is non-blocking

NOTE: writing to a blocking output stream will block the calling thread until all given data can be consumed by the stream.

void nsISeekableStream::seek ( in long  whence,
in long long  offset 
) [inherited]

seek

This method moves the stream offset of the steam implementing this interface.

Parameters:
whencespecifies how to interpret the 'offset' parameter in setting the stream offset associated with the implementing stream.
offsetspecifies a value, in bytes, that is used in conjunction with the 'whence' parameter to set the stream offset of the implementing stream. A negative value causes seeking in the reverse direction.

setEOF

This method truncates the stream at the current offset.

tell

This method reports the current offset, in bytes, from the start of the stream.

unsigned long nsIOutputStream::write ( in string  aBuf,
in unsigned long  aCount 
) [inherited]

Write data into the stream.

Parameters:
aBufthe buffer containing the data to be written
aCountthe maximum number of bytes to be written
Returns:
number of bytes written (may be less than aCount)
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif writing to the output stream would block the calling thread (non-blocking mode only)
<other-error>on failure
NS_IMETHODIMP nsSafeFileOutputStream::Write ( const char *  buf,
PRUint32  count,
PRUint32 result 
)

Definition at line 605 of file nsFileStreams.cpp.

{
    nsresult rv = nsFileOutputStream::Write(buf, count, result);
    if (NS_SUCCEEDED(mWriteResult)) {
        if (NS_FAILED(rv))
            mWriteResult = rv;
        else if (count != *result)
            mWriteResult = NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;

        if (NS_FAILED(mWriteResult) && count > 0)
            NS_WARNING("writing to output stream failed! data may be lost");
    } 
    return rv;
}
unsigned long nsIOutputStream::writeFrom ( in nsIInputStream  aFromStream,
in unsigned long  aCount 
) [inherited]

Writes data into the stream from an input stream.

Parameters:
aFromStreamthe stream containing the data to be written
aCountthe maximum number of bytes to be written
Returns:
number of bytes written (may be less than aCount)
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif writing to the output stream would block the calling thread (non-blocking mode only)
<other-error>on failure

NOTE: This method is defined by this interface in order to allow the output stream to efficiently copy the data from the input stream into its internal buffer (if any). If this method was provided as an external facility, a separate char* buffer would need to be used in order to call the output stream's other Write method.

unsigned long nsIOutputStream::writeSegments ( in nsReadSegmentFun  aReader,
in voidPtr  aClosure,
in unsigned long  aCount 
) [inherited]

Low-level write method that has access to the stream's underlying buffer.

The reader function may be called multiple times for segmented buffers. WriteSegments is expected to keep calling the reader until either there is nothing left to write or the reader returns an error. WriteSegments should not call the reader with zero bytes to provide.

Parameters:
aReaderthe "provider" of the data to be written
aClosureopaque parameter passed to reader
aCountthe maximum number of bytes to be written
Returns:
number of bytes written (may be less than aCount)
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif writing to the output stream would block the calling thread (non-blocking mode only)
<other-error>on failure

NOTE: this function may be unimplemented if a stream has no underlying buffer (e.g., socket output stream).


Member Data Documentation

PRBool nsFileStream::mCloseFD [protected, inherited]

Definition at line 72 of file nsFileStreams.h.

PRFileDesc* nsFileStream::mFD [protected, inherited]

Definition at line 69 of file nsFileStreams.h.

nsCOMPtr<nsISupports> nsFileStream::mParent [protected, inherited]

Definition at line 70 of file nsFileStreams.h.

Definition at line 175 of file nsFileStreams.h.

Definition at line 178 of file nsFileStreams.h.

Definition at line 176 of file nsFileStreams.h.

Definition at line 179 of file nsFileStreams.h.

Definition at line 62 of file nsISeekableStream.idl.

Definition at line 68 of file nsISeekableStream.idl.

Definition at line 56 of file nsISeekableStream.idl.


The documentation for this class was generated from the following files: