FileStreamWriter Class Reference

#include <streamwriter.h>

Inheritance diagram for FileStreamWriter:
StreamWriter

List of all members.

Public Member Functions

 FileStreamWriter (FILE *fA, Guint startA, GBool limitedA, Guint lengthA, Object *dictA)
virtual ~FileStreamWriter ()
virtual void putChar (int ch)
virtual void putLine (const char *line, size_t length)
virtual bool trim (size_t pos)
virtual void flush () const
virtual size_t cloneToFile (FILE *file, size_t start, size_t length)

Detailed Description

FileStream writer.

Implements BaseStreamWriter and FileStream to enable writing to the file stream.


Constructor & Destructor Documentation

FileStreamWriter::FileStreamWriter ( FILE *  fA,
Guint  startA,
GBool  limitedA,
Guint  lengthA,
Object *  dictA 
) [inline]

Costructor.

Parameters:
fA File handle for stream.
startA Start offset in the file.
limitedA Limited flag for stream (true if stream has limited size).
lengthA Length of the stream (ignored if limitedA is false).
dictA Dictionary for the stream (should be initialized as NULL object).

Calls BaseStream and StreamWriter constructors with given dictA parameter and initializes FileStream super type with fA, startA, limitedA and dictA parameters.

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

Destructor for FileStreamWriter.

NOTE: doesn't close given file handle. Instance creator is responsible to that. The reason for this is based on xpdf usage of streams in general. Xpdf Parser/Lexer classes use higly Stream::makeSubStream method to get only subset (limited range) of the stream data and when they are finieshed, this substream is deallocated. FileStream, in turn, creates such a substream that shares file handle with the original one. Therefore FileStream and also all descendants *MUST NOT* close file handle in destructor. This is the case also for this class. Otherwise we would have invalid file handle in the original stream after substream is not needed (and deallocated).


Member Function Documentation

size_t FileStreamWriter::cloneToFile ( FILE *  file,
size_t  start,
size_t  length 
) [virtual]

Duplicates content to given file.

Parameters:
file File where to put duplicated content.
start Position where to start duplication.
length Number of bytes to be duplicated.

Copies up to length bytes from start postion from stream to given file. If length is 0, copies content until end of stream.

Returns:
number of bytes writen to given file.

Implements StreamWriter.

References debug::DBG_DBG, debug::DBG_ERR, debug::DBG_INFO, kernelPrintDbg, and _JM_NAMESPACE::min().

virtual void FileStreamWriter::flush (  )  const [inline, virtual]

Forces file flush.

Calls fflush on the file handle.

Implements StreamWriter.

Referenced by trim().

void FileStreamWriter::putChar ( int  ch  )  [virtual]

Puts character to the file.

Parameters:
ch Character to write.

Additionally flushes all changes to the file and position is moved after inserted character.

See also:
BaseStreamWriter::putChar

Implements StreamWriter.

void FileStreamWriter::putLine ( const char *  line,
size_t  length 
) [virtual]

Puts exactly length number of byte to one line.

Parameters:
line Line buffer pointer.
length Number of bytes to be printed.

Prints exactly length number of bytes starting from given line. Additionally flushes all changes to the file and position is moved after inserted buffer. Appends LF after given string.

Implements StreamWriter.

References debug::DBG_ERR, and kernelPrintDbg.

bool FileStreamWriter::trim ( size_t  pos  )  [virtual]

Removes all data behind given file offset position.

Parameters:
pos Stream offset where to start removing.

Calls ftruncate function to truncate underlaying FILE stream to the start+pos size (pos is relative position to stream start NOT absolut file start). FILE stream is flushed before and after truncation.
This method can be used when there is some pending garbage behind usuful data. File size is changed as a side effect. Note that if pos is greater than current file size, file will be appended with NUL characters (binary 0). If current stream position is in truncated area, it is moved to the stream end.
Note that this operation may fail, if stream is limited and given pos is out of border:

 pos>length
 
Returns:
true if stream was trimed, false otherwise.

Implements StreamWriter.

References debug::DBG_DBG, debug::DBG_ERR, flush(), and kernelPrintDbg.


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