<class name="QBuffer" doc="/** <p>The <a href="QBuffer.html#QBuffer(com.trolltech.qt.core.QObject)"><tt>QBuffer</tt></a> class provides a <a href="QIODevice.html#QIODevice(com.trolltech.qt.core.QObject)"><tt>QIODevice</tt></a> interface for a <a href="QByteArray.html"><tt>QByteArray</tt></a>.</p> <p><a href="QBuffer.html#QBuffer(com.trolltech.qt.core.QObject)"><tt>QBuffer</tt></a> allows you to access a <a href="QByteArray.html"><tt>QByteArray</tt></a> using the <a href="QIODevice.html#QIODevice(com.trolltech.qt.core.QObject)"><tt>QIODevice</tt></a> interface. The <a href="QByteArray.html"><tt>QByteArray</tt></a> is treated just as a standard random-accessed file. Example:</p> <pre> QBuffer buffer; char ch; buffer.open(QBuffer::ReadWrite); buffer.write(&quot;Qt rocks!&quot;); buffer.seek(0); buffer.getChar(&amp;ch); <span class="comment">// ch == 'Q'</span> buffer.getChar(&amp;ch); <span class="comment">// ch == 't'</span> buffer.getChar(&amp;ch); <span class="comment">// ch == ' '</span> buffer.getChar(&amp;ch); <span class="comment">// ch == 'r'</span></pre> <p>By default, an internal <a href="QByteArray.html"><tt>QByteArray</tt></a> buffer is created for you when you create a <a href="QBuffer.html#QBuffer(com.trolltech.qt.core.QObject)"><tt>QBuffer</tt></a>. You can access this buffer directly by calling <a href="QBuffer.html#buffer()"><tt>buffer</tt></a>. You can also use <a href="QBuffer.html#QBuffer(com.trolltech.qt.core.QObject)"><tt>QBuffer</tt></a> with an existing <a href="QByteArray.html"><tt>QByteArray</tt></a> by calling setBuffer(), or by passing your array to <a href="QBuffer.html#QBuffer(com.trolltech.qt.core.QObject)"><tt>QBuffer</tt></a>'s constructor.</p> <p>Call <a href="QBuffer.html#open(com.trolltech.qt.core.QIODevice.OpenMode)"><tt>open</tt></a> to open the buffer. Then call <a href="QIODevice.html#write(com.trolltech.qt.core.QByteArray)"><tt>write</tt></a> or putChar() to write to the buffer, and <a href="QIODevice.html#read(long)"><tt>read</tt></a>, <a href="QIODevice.html#readLine(long)"><tt>readLine</tt></a>, <a href="QIODevice.html#readAll()"><tt>readAll</tt></a>, or getChar() to read from it. <a href="QBuffer.html#size()"><tt>size</tt></a> returns the current size of the buffer, and you can seek to arbitrary positions in the buffer by calling <a href="QBuffer.html#seek(long)"><tt>seek</tt></a>. When you are done with accessing the buffer, call <a href="QBuffer.html#close()"><tt>close</tt></a>.</p> <p>The following code snippet shows how to write data to a <a href="QByteArray.html"><tt>QByteArray</tt></a> using <a href="QDataStream.html"><tt>QDataStream</tt></a> and <a href="QBuffer.html#QBuffer(com.trolltech.qt.core.QObject)"><tt>QBuffer</tt></a>:</p> <pre> QByteArray byteArray; QBuffer buffer(&amp;byteArray); buffer.open(QIODevice::WriteOnly); QDataStream out(&amp;buffer); out &lt;&lt; QApplication::palette();</pre> <p>Effectively, we convert the application's <a href="%2E%2E/gui/QPalette.html"><tt>QPalette</tt></a> into a byte array. Here's how to read the data from the <a href="QByteArray.html"><tt>QByteArray</tt></a>:</p> <pre> QPalette palette; QBuffer buffer(&amp;byteArray); buffer.open(QIODevice::ReadOnly); QDataStream in(&amp;buffer); in &gt;&gt; palette;</pre> <p><a href="QTextStream.html"><tt>QTextStream</tt></a> and <a href="QDataStream.html"><tt>QDataStream</tt></a> also provide convenience constructors that take a <a href="QByteArray.html"><tt>QByteArray</tt></a> and that create a <a href="QBuffer.html#QBuffer(com.trolltech.qt.core.QObject)"><tt>QBuffer</tt></a> behind the scenes.</p> <p><a href="QBuffer.html#QBuffer(com.trolltech.qt.core.QObject)"><tt>QBuffer</tt></a> emits <a href="QBuffer.html#readyRead()"><tt>readyRead</tt></a> when new data has arrived in the buffer. By connecting to this signal, you can use <a href="QBuffer.html#QBuffer(com.trolltech.qt.core.QObject)"><tt>QBuffer</tt></a> to store temporary data before processing it. For example, you can pass the buffer to <a href="%2E%2E/network/QFtp.html"><tt>QFtp</tt></a> when downloading a file from an FTP server. Whenever a new payload of data has been downloaded, <a href="QBuffer.html#readyRead()"><tt>readyRead</tt></a> is emitted, and you can process the data that just arrived. <a href="QBuffer.html#QBuffer(com.trolltech.qt.core.QObject)"><tt>QBuffer</tt></a> also emits <a href="QBuffer.html#bytesWritten(long)"><tt>bytesWritten</tt></a> every time new data has been written to the buffer.</p> @see <a href="QFile.html"><tt>QFile</tt></a> @see <a href="QDataStream.html"><tt>QDataStream</tt></a> @see <a href="QTextStream.html"><tt>QTextStream</tt></a> @see <a href="QByteArray.html"><tt>QByteArray</tt></a> */"> <signal name="protected final void aboutToClose()" doc="/** <p>This signal is emitted when the device is about to close. Connect this signal if you have operations that need to be performed before the device closes (e.g&#x2e;, if you have data in a separate buffer that needs to be written to the device).</p> <dl> <dt><b>Compatible Slot Signature:</b></dt> <dd><tt>void mySlot()</tt></dd> </dl> */"/> <signal name="protected final void bytesWritten(long bytes)" doc="/** <p>This signal is emitted every time a payload of data has been written to the device. The <tt>bytes</tt> argument is set to the number of bytes that were written in this payload.</p> <p><a href="QBuffer.html#bytesWritten(long)"><tt>bytesWritten</tt></a> is not emitted recursively; if you reenter the event loop or call <a href="QIODevice.html#waitForBytesWritten(int)"><tt>waitForBytesWritten</tt></a> inside a slot connected to the <a href="QBuffer.html#bytesWritten(long)"><tt>bytesWritten</tt></a> signal, the signal will not be reemitted (although <a href="QIODevice.html#waitForBytesWritten(int)"><tt>waitForBytesWritten</tt></a> may still return true).</p> <dl> <dt><b>Compatible Slot Signatures:</b></dt> <dd><tt>void mySlot(long bytes)</tt></dd> <dd><tt>void mySlot()</tt></dd> </dl> <dl> <dt><b>See Also:</b></dt> <dd><a href="QBuffer.html#readyRead()"><tt>readyRead</tt></a></dd> </dl> */"/> <signal name="protected final void readyRead()" doc="/** <p>This signal is emitted once every time new data is available for reading from the device. It will only be emitted again once new data is available, such as when a new payload of network data has arrived on your network socket, or when a new block of data has been appended to your device.</p> <p><a href="QBuffer.html#readyRead()"><tt>readyRead</tt></a> is not emitted recursively; if you reenter the event loop or call <a href="QIODevice.html#waitForReadyRead(int)"><tt>waitForReadyRead</tt></a> inside a slot connected to the <a href="QBuffer.html#readyRead()"><tt>readyRead</tt></a> signal, the signal will not be reemitted (although <a href="QIODevice.html#waitForReadyRead(int)"><tt>waitForReadyRead</tt></a> may still return true).</p> <dl> <dt><b>Compatible Slot Signature:</b></dt> <dd><tt>void mySlot()</tt></dd> </dl> <dl> <dt><b>See Also:</b></dt> <dd><a href="QBuffer.html#bytesWritten(long)"><tt>bytesWritten</tt></a></dd> </dl> */"/> <method name="public QBuffer(com.trolltech.qt.core.QObject parent)" doc="/** <p>Constructs an empty buffer with the given <tt>parent</tt>. You can call <a href="QBuffer.html#setData(com.trolltech.qt.core.QByteArray)"><tt>setData</tt></a> to fill the buffer with data, or you can open it in write mode and use <a href="QIODevice.html#write(com.trolltech.qt.core.QByteArray)"><tt>write</tt></a>.</p> @see <a href="QBuffer.html#open(com.trolltech.qt.core.QIODevice.OpenMode)"><tt>open</tt></a> */"/> <method name="public QBuffer()" doc="/** <p>Equivalent to <a href="QBuffer.html#QBuffer(com.trolltech.qt.core.QObject)"><tt>QBuffer</tt></a>(0). */"/> <method name="public final com.trolltech.qt.core.QByteArray buffer()" doc="/** <p>This is the same as <a href="QBuffer.html#data()"><tt>data</tt></a>.</p> */"/> <method name="public final com.trolltech.qt.core.QByteArray data()" doc="/** <p>Returns the data contained in the buffer.</p> <p>This is the same as <a href="QBuffer.html#buffer()"><tt>buffer</tt></a>.</p> @see <a href="QBuffer.html#setData(com.trolltech.qt.core.QByteArray)"><tt>setData</tt></a> @see <tt>setBuffer</tt> */"/> <method name="public final void setData(com.trolltech.qt.core.QByteArray data)" doc="/** <p>Sets the contents of the internal buffer to be <tt>data</tt>. This is the same as assigning <tt>data</tt> to <a href="QBuffer.html#buffer()"><tt>buffer</tt></a>.</p> <p>Does nothing if <a href="QIODevice.html#isOpen()"><tt>isOpen</tt></a> is true.</p> @see <a href="QBuffer.html#data()"><tt>data</tt></a> @see <tt>setBuffer</tt> */"/> <method name="public boolean atEnd()" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="public boolean canReadLine()" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="public void close()" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="public boolean open(com.trolltech.qt.core.QIODevice.OpenMode openMode)" doc="/** <p>Opens the device and sets its OpenMode to <tt>openMode</tt>. Returns true if successful; otherwise returns false.</p> @see <a href="QIODevice.html#openMode()"><tt>openMode</tt></a> @see <tt>OpenMode</tt> */"/> <method name="public long pos()" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="protected int readData(byte[] data)" doc="/** <p>Equivalent to <a href="QBuffer.html#readData(byte[])"><tt>readData</tt></a>(<tt>data</tt>, ). */"/> <method name="public boolean seek(long off)" doc="/** <p>For random-access devices, this function sets the current position to <tt>off</tt>, returning true on success, or false if an error occurred. For sequential devices, the default behavior is to do nothing and return false.</p> <p>When subclassing <a href="QIODevice.html#QIODevice(com.trolltech.qt.core.QObject)"><tt>QIODevice</tt></a>, you must call QIODevice::seek() at the start of your function to ensure integrity with <a href="QIODevice.html#QIODevice(com.trolltech.qt.core.QObject)"><tt>QIODevice</tt></a>'s built-in buffer. The base implementation always returns true.</p> @see <a href="QBuffer.html#pos()"><tt>pos</tt></a> @see <a href="QIODevice.html#isSequential()"><tt>isSequential</tt></a> */"/> <method name="public long size()" doc="/** <p>This function is reimplemented for internal reasons.</p> */"/> <method name="protected int writeData(byte[] data)" doc="/** <p>Equivalent to <a href="QBuffer.html#writeData(byte[])"><tt>writeData</tt></a>(<tt>data</tt>, ). */"/> </class>