Qt 4.8
Public Functions | Static Public Functions | Protected Functions | Private Functions | Properties | List of all members
QPdf::ByteStream Class Reference

#include <qpdf_p.h>

Inheritance diagram for QPdf::ByteStream:
QPdfPage

Public Functions

 ByteStream (bool fileBacking=false)
 
 ByteStream (QByteArray *ba, bool fileBacking=false)
 
void clear ()
 
ByteStreamoperator<< (char chr)
 
ByteStreamoperator<< (const char *str)
 
ByteStreamoperator<< (const QByteArray &str)
 
ByteStreamoperator<< (const ByteStream &src)
 
ByteStreamoperator<< (qreal val)
 
ByteStreamoperator<< (int val)
 
ByteStreamoperator<< (const QPointF &p)
 
QIODevicestream ()
 
 ~ByteStream ()
 

Static Public Functions

static int chunkSize ()
 
static int maxMemorySize ()
 

Protected Functions

void constructor_helper (QIODevice *dev)
 
void constructor_helper (QByteArray *ba)
 

Private Functions

void prepareBuffer ()
 

Properties

QByteArray ba
 
QIODevicedev
 
bool fileBackingActive
 
bool fileBackingEnabled
 
bool handleDirty
 

Detailed Description

Definition at line 80 of file qpdf_p.h.

Constructors and Destructors

◆ ByteStream() [1/2]

QPdf::ByteStream::ByteStream ( bool  fileBacking = false)
explicit

Definition at line 150 of file qpdf.cpp.

151  : dev(new QBuffer(&ba)),
152  fileBackingEnabled(fileBacking),
153  fileBackingActive(false),
154  handleDirty(false)
155  {
157  }
bool fileBackingEnabled
Definition: qpdf_p.h:114
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
bool fileBackingActive
Definition: qpdf_p.h:115
QByteArray ba
Definition: qpdf_p.h:113
bool handleDirty
Definition: qpdf_p.h:116
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
QIODevice * dev
Definition: qpdf_p.h:112

◆ ByteStream() [2/2]

QPdf::ByteStream::ByteStream ( QByteArray ba,
bool  fileBacking = false 
)
explicit

Definition at line 141 of file qpdf.cpp.

142  : dev(new QBuffer(byteArray)),
143  fileBackingEnabled(fileBacking),
144  fileBackingActive(false),
145  handleDirty(false)
146  {
148  }
bool fileBackingEnabled
Definition: qpdf_p.h:114
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
bool fileBackingActive
Definition: qpdf_p.h:115
bool handleDirty
Definition: qpdf_p.h:116
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
QIODevice * dev
Definition: qpdf_p.h:112

◆ ~ByteStream()

QPdf::ByteStream::~ByteStream ( )

Definition at line 159 of file qpdf.cpp.

160  {
161  delete dev;
162  }
QIODevice * dev
Definition: qpdf_p.h:112

Functions

◆ chunkSize()

static int QPdf::ByteStream::chunkSize ( )
inlinestatic

Definition at line 102 of file qpdf_p.h.

Referenced by QPSPrintEnginePrivate::emitPages(), operator<<(), prepareBuffer(), and QPdfEnginePrivate::writeCompressed().

102 { return 10000000; }

◆ clear()

void QPdf::ByteStream::clear ( )

Definition at line 232 of file qpdf.cpp.

Referenced by QPSPrintEnginePrivate::emitPages(), and QPSPrintEnginePrivate::flushPage().

233  {
235  }
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
QIODevice * dev
Definition: qpdf_p.h:112

◆ constructor_helper() [1/2]

void QPdf::ByteStream::constructor_helper ( QIODevice dev)
protected

Referenced by chunkSize().

◆ constructor_helper() [2/2]

void QPdf::ByteStream::constructor_helper ( QByteArray ba)
protected

Definition at line 237 of file qpdf.cpp.

238  {
239  delete dev;
240  dev = new QBuffer(ba);
242  }
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
QIODevice * dev
Definition: qpdf_p.h:112

◆ maxMemorySize()

static int QPdf::ByteStream::maxMemorySize ( )
inlinestatic

Definition at line 101 of file qpdf_p.h.

Referenced by prepareBuffer().

101 { return 100000000; }

◆ operator<<() [1/7]

ByteStream & QPdf::ByteStream::operator<< ( char  chr)

Definition at line 164 of file qpdf.cpp.

165  {
166  if (handleDirty) prepareBuffer();
167  dev->write(&chr, 1);
168  return *this;
169  }
bool handleDirty
Definition: qpdf_p.h:116
void prepareBuffer()
Definition: qpdf.cpp:244
QIODevice * dev
Definition: qpdf_p.h:112
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342

◆ operator<<() [2/7]

ByteStream & QPdf::ByteStream::operator<< ( const char *  str)

Definition at line 171 of file qpdf.cpp.

172  {
173  if (handleDirty) prepareBuffer();
174  dev->write(str, strlen(str));
175  return *this;
176  }
bool handleDirty
Definition: qpdf_p.h:116
void prepareBuffer()
Definition: qpdf.cpp:244
QIODevice * dev
Definition: qpdf_p.h:112
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342

◆ operator<<() [3/7]

ByteStream & QPdf::ByteStream::operator<< ( const QByteArray str)

Definition at line 178 of file qpdf.cpp.

179  {
180  if (handleDirty) prepareBuffer();
181  dev->write(str);
182  return *this;
183  }
bool handleDirty
Definition: qpdf_p.h:116
void prepareBuffer()
Definition: qpdf.cpp:244
QIODevice * dev
Definition: qpdf_p.h:112
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342

◆ operator<<() [4/7]

ByteStream & QPdf::ByteStream::operator<< ( const ByteStream src)

Definition at line 185 of file qpdf.cpp.

186  {
187  Q_ASSERT(!src.dev->isSequential());
188  if (handleDirty) prepareBuffer();
189  // We do play nice here, even though it looks ugly.
190  // We save the position and restore it afterwards.
191  ByteStream &s = const_cast<ByteStream&>(src);
192  qint64 pos = s.dev->pos();
193  s.dev->reset();
194  while (!s.dev->atEnd()) {
195  QByteArray buf = s.dev->read(chunkSize());
196  dev->write(buf);
197  }
198  s.dev->seek(pos);
199  return *this;
200  }
static int chunkSize()
Definition: qpdf_p.h:102
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
ByteStream(bool fileBacking=false)
Definition: qpdf.cpp:150
__int64 qint64
Definition: qglobal.h:942
bool handleDirty
Definition: qpdf_p.h:116
void prepareBuffer()
Definition: qpdf.cpp:244
QIODevice * dev
Definition: qpdf_p.h:112
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342

◆ operator<<() [5/7]

ByteStream & QPdf::ByteStream::operator<< ( qreal  val)

Definition at line 202 of file qpdf.cpp.

202  {
203  char buf[256];
204  qt_real_to_string(val, buf);
205  *this << buf;
206  return *this;
207  }
const char * qt_real_to_string(qreal val, char *buf)
Definition: qpdf.cpp:63

◆ operator<<() [6/7]

ByteStream & QPdf::ByteStream::operator<< ( int  val)

Definition at line 209 of file qpdf.cpp.

209  {
210  char buf[256];
211  qt_int_to_string(val, buf);
212  *this << buf;
213  return *this;
214  }
const char * qt_int_to_string(int val, char *buf)
Definition: qpdf.cpp:115

◆ operator<<() [7/7]

ByteStream & QPdf::ByteStream::operator<< ( const QPointF p)

Definition at line 216 of file qpdf.cpp.

216  {
217  char buf[256];
218  qt_real_to_string(p.x(), buf);
219  *this << buf;
220  qt_real_to_string(p.y(), buf);
221  *this << buf;
222  return *this;
223  }
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
const char * qt_real_to_string(qreal val, char *buf)
Definition: qpdf.cpp:63
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ prepareBuffer()

void QPdf::ByteStream::prepareBuffer ( )
private

Definition at line 244 of file qpdf.cpp.

Referenced by chunkSize(), and operator<<().

245  {
247  qint64 size = dev->size();
249  && size > maxMemorySize()) {
250  // Switch to file backing.
251  QTemporaryFile *newFile = new QTemporaryFile;
252  newFile->open();
253  dev->reset();
254  while (!dev->atEnd()) {
255  QByteArray buf = dev->read(chunkSize());
256  newFile->write(buf);
257  }
258  delete dev;
259  dev = newFile;
260  ba.clear();
261  fileBackingActive = true;
262  }
263  if (dev->pos() != size) {
264  dev->seek(size);
265  handleDirty = false;
266  }
267  }
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Definition: qiodevice.cpp:642
static int chunkSize()
Definition: qpdf_p.h:102
bool fileBackingEnabled
Definition: qpdf_p.h:114
static int maxMemorySize()
Definition: qpdf_p.h:101
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QTemporaryFile class is an I/O device that operates on temporary files.
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
Definition: qiodevice.cpp:624
bool open()
A QTemporaryFile will always be opened in QIODevice::ReadWrite mode, this allows easy access to the d...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual bool atEnd() const
Returns true if the current read and write position is at the end of the device (i.e.
Definition: qiodevice.cpp:711
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
bool fileBackingActive
Definition: qpdf_p.h:115
QByteArray ba
Definition: qpdf_p.h:113
__int64 qint64
Definition: qglobal.h:942
bool handleDirty
Definition: qpdf_p.h:116
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
Definition: qiodevice.cpp:454
virtual bool reset()
Seeks to the start of input for random-access devices.
Definition: qiodevice.cpp:732
QIODevice * dev
Definition: qpdf_p.h:112
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
Definition: qiodevice.cpp:659
void clear()
Clears the contents of the byte array and makes it empty.

◆ stream()

QIODevice * QPdf::ByteStream::stream ( )

Definition at line 225 of file qpdf.cpp.

Referenced by QPSPrintEnginePrivate::emitPages(), QPSPrintEnginePrivate::flushPage(), and QPdfEnginePrivate::writePage().

226  {
227  dev->reset();
228  handleDirty = true;
229  return dev;
230  }
bool handleDirty
Definition: qpdf_p.h:116
virtual bool reset()
Seeks to the start of input for random-access devices.
Definition: qiodevice.cpp:732
QIODevice * dev
Definition: qpdf_p.h:112

Properties

◆ ba

QByteArray QPdf::ByteStream::ba
private

Definition at line 113 of file qpdf_p.h.

Referenced by prepareBuffer().

◆ dev

QIODevice* QPdf::ByteStream::dev
private

◆ fileBackingActive

bool QPdf::ByteStream::fileBackingActive
private

Definition at line 115 of file qpdf_p.h.

Referenced by prepareBuffer().

◆ fileBackingEnabled

bool QPdf::ByteStream::fileBackingEnabled
private

Definition at line 114 of file qpdf_p.h.

Referenced by prepareBuffer().

◆ handleDirty

bool QPdf::ByteStream::handleDirty
private

Definition at line 116 of file qpdf_p.h.

Referenced by operator<<(), prepareBuffer(), and stream().


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