NFile Class Reference

NFile class is used to abstract file manipulation. More...

Inheritance diagram for NFile:

NIODevice NObject

List of all members.

Public Member Functions

 NFile (void)
 Constructs a NFile object.
 NFile (const NString &path, NIODevice::Mode mode=NIODevice::ReadWrite)
 Constructs a NFile object.
 ~NFile (void)
 Destroys a NFile object releasing used resources.
bool atEnd (void) const
 Tests whether the file is at the end.
bool exists (void) const
 Tests whether the file exists.
int handle (void) const
 Obtains the current file handle.
void open (NIODevice::Mode mode)
 Opens the file.
void closeDevice (void)
 Closes the file.
nint32 read (NDataStream *buffer)
 Reads data from the file.
nint32 read (NDataStream *buffer, nuint32 bytes)
 Reads at most 'bytes' of data from the file.
nint32 readLine (NDataStream *buffer)
 Reads data from the file until find a newline.
nint32 write (const NDataStream &data, nuint32 bytes=0)
 Writes data to the file.
nint64 size (void) const
 Returns the size of the file.
void setFileName (const NString &path)
 Sets the name of the file to manipulate.
NString getFileName (void) const
 Gets the name of the file to manipulate.

Static Public Member Functions

static bool exists (const NString &filepath)
 Tests whether the file exists.


Detailed Description

NFile class is used to abstract file manipulation.
Examples:

ex_nfile.cpp.

Definition at line 45 of file nfile.h.


Constructor & Destructor Documentation

NFile ( const NString path,
NIODevice::Mode  mode = NIODevice::ReadWrite 
)

Constructs a NFile object.

Parameters:
path The path of the file to open
mode The mode to open the file as defined by the enum NIODevice::Mode

Definition at line 32 of file nfile.cpp.

References open(), and setFileName().


Member Function Documentation

bool atEnd ( void   )  const

Tests whether the file is at the end.

Returns:
true if it is at the end or false otherwise

Definition at line 47 of file nfile.cpp.

Referenced by NShaHash::calculateFile(), NSha1Hash::calculateFile(), NMd5Hash::calculateFile(), NMd4Hash::calculateFile(), and NMd2Hash::calculateFile().

bool exists ( void   )  const

Tests whether the file exists.

Returns:
true if it exists or false otherwise
Examples:
ex_nfile.cpp.

Definition at line 56 of file nfile.cpp.

References NException::BASEIO, NIOException::FILE, and NString::toChar().

Referenced by open().

bool exists ( const NString filepath  )  [static]

Tests whether the file exists.

Parameters:
filepath A filename with the path to it.
Returns:
true if it exists or false otherwise

Definition at line 73 of file nfile.cpp.

References NException::BASEIO, NIOException::FILE, and NString::toChar().

int handle ( void   )  const

Obtains the current file handle.

Returns:
An signed integer representing the file handle
Note:
Please note that you must not close the file handle or you may break your program

Definition at line 90 of file nfile.cpp.

Referenced by NXmlSchemaParser::parse(), NXmlParser::parse(), and size().

void open ( NIODevice::Mode  mode  )  [virtual]

Opens the file.

Parameters:
mode The mode to open the file as defined by the enum NIODevice::Mode
Note:
Please note that this method may throw an exception of type NException

Implements NIODevice.

Examples:
ex_nfile.cpp.

Definition at line 113 of file nfile.cpp.

References NException::BASEIO, exists(), NIOException::FILE, NIOException::getFlagByErr(), NIODevice::ReadOnly, and NString::toChar().

Referenced by NFile().

nint32 read ( NDataStream buffer  )  [virtual]

Reads data from the file.

Parameters:
buffer A NDataStream buffer to store read data
Returns:
The amount of bytes read or -1 if there's any error with the handle

Implements NIODevice.

Definition at line 141 of file nfile.cpp.

References NIODevice::m_readBufferSize, and NDataStream::set().

Referenced by NShaHash::calculateFile(), NSha1Hash::calculateFile(), NMd5Hash::calculateFile(), NMd4Hash::calculateFile(), and NMd2Hash::calculateFile().

nint32 read ( NDataStream buffer,
nuint32  bytes 
) [virtual]

Reads at most 'bytes' of data from the file.

Parameters:
buffer A NDataStream buffer to store read data
bytes Max number of bytes to read
Returns:
The amount of bytes read or -1 if there's any error with the handle

Implements NIODevice.

Definition at line 162 of file nfile.cpp.

References NDataStream::append().

nint32 readLine ( NDataStream buffer  )  [virtual]

Reads data from the file until find a newline.

Parameters:
buffer A NDataStream buffer to store read data
Returns:
The amount of bytes read or -1 if there's any error with the handle

Implements NIODevice.

Definition at line 187 of file nfile.cpp.

References NDataStream::append().

nint32 write ( const NDataStream data,
nuint32  bytes = 0 
) [virtual]

Writes data to the file.

Parameters:
data Data to be written to the file
bytes Max number of bytes to write
Returns:
The amount of bytes written or -1 if there's any error with the handle

Implements NIODevice.

Examples:
ex_nfile.cpp.

Definition at line 211 of file nfile.cpp.

References NDataStream::data(), and NDataStream::size().

nint64 size ( void   )  const

Returns the size of the file.

Returns:
The size, in bytes, of the file

Definition at line 228 of file nfile.cpp.

References NException::BASEIO, NIOException::FILE, and handle().

void setFileName ( const NString path  ) 

Sets the name of the file to manipulate.

Parameters:
path The path of the file
Examples:
ex_nfile.cpp.

Definition at line 242 of file nfile.cpp.

References closeDevice(), and NString::isNull().

Referenced by NFile().

NString getFileName ( void   )  const

Gets the name of the file to manipulate.

Returns:
The full path to the file
Examples:
ex_nfile.cpp.

Definition at line 251 of file nfile.cpp.


The documentation for this class was generated from the following files:
Generated on Wed Mar 5 23:10:36 2008 for NemesisUtilitiesSystem by  doxygen 1.5.4