Back to index

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

#include <nsFileStreams.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIINPUTSTREAM
NS_DECL_NSIFILEINPUTSTREAM
NS_DECL_NSILINEINPUTSTREAM
NS_IMETHOD 
Seek (PRInt32 aWhence, PRInt64 aOffset)
 nsFileInputStream ()
virtual ~nsFileInputStream ()
nsresult Close ()
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.
unsigned long available ()
unsigned long read (in charPtr aBuf, in unsigned long aCount)
 Read data from the stream.
unsigned long readSegments (in nsWriteSegmentFun aWriter, in voidPtr aClosure, in unsigned long aCount)
 Low-level read method that has access to the stream's underlying buffer.
boolean isNonBlocking ()
boolean readLine (out ACString aLine)
 Read a single line from the stream, where a line is a possibly zero length sequence of 8bit chars terminated by a CR, LF, CRLF, LFCR, or eof.

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
const long DELETE_ON_CLOSE = 1<<1
 If this is set, the file will be deleted by the time the stream is closed.
const long CLOSE_ON_EOF = 1<<2
 If this is set, the file will close automatically when the end of the file is reached.
const long REOPEN_ON_REWIND = 1<<3
 If this is set, the file will be reopened whenever Seek(0) occurs.

Protected Member Functions

nsresult Open (nsIFile *file, PRInt32 ioFlags, PRInt32 perm)
 Internal, called to open a file.
nsresult Reopen ()
 Reopen the file (for OPEN_ON_READ only!)

Protected Attributes

nsLineBuffer< char > * mLineBuffer
nsCOMPtr< nsIFilemFile
 The file being opened.
PRInt32 mIOFlags
 The IO flags passed to Init() for the file open.
PRInt32 mPerm
 The permissions passed to Init() for the file open.
PRInt32 mBehaviorFlags
 Flags describing our behavior.
PRFileDescmFD
nsCOMPtr< nsISupports > mParent
PRBool mCloseFD

Detailed Description

Definition at line 77 of file nsFileStreams.h.


Constructor & Destructor Documentation

Definition at line 90 of file nsFileStreams.h.

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

Definition at line 95 of file nsFileStreams.h.

    {
        Close();
    }

Here is the call graph for this function:


Member Function Documentation

unsigned long nsIInputStream::available ( ) [inherited]
Returns:
number of bytes currently available in the stream
nsresult nsFileStream::Close ( void  ) [inherited]

Reimplemented in nsSafeFileOutputStream.

Definition at line 121 of file nsFileStreams.cpp.

{
    nsresult rv = NS_OK;
    if (mFD) {
        if (mCloseFD)
            if (PR_Close(mFD) == PR_FAILURE)
                rv = NS_BASE_STREAM_OSERROR;
        mFD = nsnull;
    }
    return rv;
}

Here is the caller graph for this function:

void nsIInputStream::close ( ) [inherited]

Close the stream.

static NS_METHOD nsFileInputStream::Create ( nsISupports *  aOuter,
REFNSIID  aIID,
void **  aResult 
) [static]
void nsIFileInputStream::init ( in nsIFile  file,
in long  ioFlags,
in long  perm,
in long  behaviorFlags 
) [inherited]
Parameters:
filefile to read from (must QI to nsILocalFile)
ioFlagsfile open flags listed in prio.h
permfile mode bits listed in prio.h
behaviorFlagsflags specifying various behaviors of the class (see enumerations in the class)
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
nsresult nsFileInputStream::Open ( nsIFile file,
PRInt32  ioFlags,
PRInt32  perm 
) [protected]

Internal, called to open a file.

Parameters are the same as their Init() analogues.

Definition at line 224 of file nsFileStreams.cpp.

{   
    nsresult rv = NS_OK;

    // If the previous file is open, close it
    if (mFD) {
        rv = Close();
        if (NS_FAILED(rv)) return rv;
    }

    // Open the file
    nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(aFile, &rv);
    if (NS_FAILED(rv)) return rv;
    if (aIOFlags == -1)
        aIOFlags = PR_RDONLY;
    if (aPerm == -1)
        aPerm = 0;

    PRFileDesc* fd;
    rv = localFile->OpenNSPRFileDesc(aIOFlags, aPerm, &fd);
    if (NS_FAILED(rv)) return rv;

    mFD = fd;

    if (mBehaviorFlags & DELETE_ON_CLOSE) {
        // POSIX compatible filesystems allow a file to be unlinked while a
        // file descriptor is still referencing the file.  since we've already
        // opened the file descriptor, we'll try to remove the file.  if that
        // fails, then we'll just remember the nsIFile and remove it after we
        // close the file descriptor.
        rv = aFile->Remove(PR_FALSE);
        if (NS_FAILED(rv) && !(mBehaviorFlags & REOPEN_ON_REWIND)) {
            // If REOPEN_ON_REWIND is not happenin', we haven't saved the file yet
            mFile = aFile;
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned long nsIInputStream::read ( in charPtr  aBuf,
in unsigned long  aCount 
) [inherited]

Read data from the stream.

Parameters:
aBufthe buffer into which the data is to be read
aCountthe maximum number of bytes to be read
Returns:
number of bytes read (may be less than aCount).
0 if reached end of file
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif reading from the input stream would block the calling thread (non-blocking mode only)
<other-error>on failure
boolean nsILineInputStream::readLine ( out ACString  aLine) [inherited]

Read a single line from the stream, where a line is a possibly zero length sequence of 8bit chars terminated by a CR, LF, CRLF, LFCR, or eof.

The line terminator is not returned.

Return values:
falseEnd of file. This line is the last line of the file (aLine is valid).
trueThe file contains further lines.
Note:
Do not mix readLine with other read functions. Doing so can cause various problems and is not supported.
unsigned long nsIInputStream::readSegments ( in nsWriteSegmentFun  aWriter,
in voidPtr  aClosure,
in unsigned long  aCount 
) [inherited]

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

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

Parameters:
aWriterthe "consumer" of the data to be read
aClosureopaque parameter passed to writer
aCountthe maximum number of bytes to be read
Returns:
number of bytes read (may be less than aCount)
0 if reached end of file (or if aWriter refused to consume data)
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif reading from the input 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 input stream).

nsresult nsFileInputStream::Reopen ( ) [inline, protected]

Reopen the file (for OPEN_ON_READ only!)

Definition at line 135 of file nsFileStreams.h.

{ return Open(mFile, mIOFlags, mPerm); }

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Definition at line 367 of file nsFileStreams.cpp.

{
    PR_FREEIF(mLineBuffer); // this invalidates the line buffer
    if (!mFD) {
        if (mBehaviorFlags & REOPEN_ON_REWIND) {
            nsresult rv = Reopen();
            if (NS_FAILED(rv)) {
                return rv;
            }
        } else {
            return NS_BASE_STREAM_CLOSED;
        }
    }

    return nsFileStream::Seek(aWhence, aOffset);
}

Here is the call graph for this function:

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.


Member Data Documentation

If this is set, the file will close automatically when the end of the file is reached.

Definition at line 73 of file nsIFileStreams.idl.

If this is set, the file will be deleted by the time the stream is closed.

It may be removed before the stream is closed if it is possible to delete it and still read from it.

If OPEN_ON_READ is defined, and the file was recreated after the first delete, the file will be deleted again when it is closed again.

Definition at line 67 of file nsIFileStreams.idl.

Flags describing our behavior.

See the IDL file for possible values.

Definition at line 124 of file nsFileStreams.h.

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.

The file being opened.

Only stored when DELETE_ON_CLOSE or REOPEN_ON_REWIND are true.

Definition at line 110 of file nsFileStreams.h.

The IO flags passed to Init() for the file open.

Only set for REOPEN_ON_REWIND.

Definition at line 115 of file nsFileStreams.h.

Definition at line 104 of file nsFileStreams.h.

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

Definition at line 70 of file nsFileStreams.h.

The permissions passed to Init() for the file open.

Only set for REOPEN_ON_REWIND.

Definition at line 120 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.

If this is set, the file will be reopened whenever Seek(0) occurs.

If the file is already open and the seek occurs, it will happen naturally. (The file will only be reopened if it is closed for some reason.)

Definition at line 80 of file nsIFileStreams.idl.


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