#include <streamwriter.h>
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) |
FileStream writer.
Implements BaseStreamWriter and FileStream to enable writing to the file stream.
| FileStreamWriter::FileStreamWriter | ( | FILE * | fA, | |
| Guint | startA, | |||
| GBool | limitedA, | |||
| Guint | lengthA, | |||
| Object * | dictA | |||
| ) | [inline] |
Costructor.
| 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).
| size_t FileStreamWriter::cloneToFile | ( | FILE * | file, | |
| size_t | start, | |||
| size_t | length | |||
| ) | [virtual] |
Duplicates content to given file.
| 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.
Implements StreamWriter.
References debug::DBG_DBG, debug::DBG_ERR, debug::DBG_INFO, kernelPrintDbg, and _JM_NAMESPACE::min().
| virtual void FileStreamWriter::flush | ( | ) | const [inline, virtual] |
| void FileStreamWriter::putChar | ( | int | ch | ) | [virtual] |
Puts character to the file.
| ch | Character to write. |
Additionally flushes all changes to the file and position is moved after inserted character.
Implements StreamWriter.
| void FileStreamWriter::putLine | ( | const char * | line, | |
| size_t | length | |||
| ) | [virtual] |
Puts exactly length number of byte to one line.
| 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.
| 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
Implements StreamWriter.
References debug::DBG_DBG, debug::DBG_ERR, flush(), and kernelPrintDbg.